TypeError: Object of type 'Decimal' is not JSON serializable

Bug #1873377 reported by licanwei on 2020-04-17
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
watcher
Undecided
licanwei

Bug Description

ft1.18: watcher.tests.api.v1.test_actions_plans.TestActionPlanPolicyEnforcementWithAdminContext.test_get_one_oktesttools.testresult.real._StringException: Traceback (most recent call last):
  File "/home/zuul/src/opendev.org/openstack/watcher/watcher/tests/api/v1/test_actions_plans.py", line 70, in test_get_one_ok
    response = self.get_json('/action_plans/%s' % action_plan['uuid'])
  File "/home/zuul/src/opendev.org/openstack/watcher/watcher/tests/api/base.py", line 233, in get_json
    expect_errors=expect_errors)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/webtest/app.py", line 328, in get
    expect_errors=expect_errors)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/webtest/app.py", line 623, in do_request
    res = req.get_response(app, catch_exc_info=True)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/webob/request.py", line 1310, in send
    application, catch_exc_info=True)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/webob/request.py", line 1278, in call_application
    app_iter = application(self.environ, start_response)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/webtest/lint.py", line 201, in lint_app
    iterator = application(environ, start_response_wrapper)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/pecan/middleware/recursive.py", line 56, in __call__
    return self.application(environ, start_response)
  File "/home/zuul/src/opendev.org/openstack/watcher/watcher/api/middleware/parsable_error.py", line 67, in __call__
    app_iter = self.app(environ, replacement_start_response)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/pecan/core.py", line 840, in __call__
    return super(Pecan, self).__call__(environ, start_response)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/pecan/core.py", line 683, in __call__
    self.invoke_controller(controller, args, kwargs, state)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/pecan/core.py", line 604, in invoke_controller
    result = self.render(template, result)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/pecan/core.py", line 425, in render
    return renderer.render(template, namespace)
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/wsmeext/pecan.py", line 27, in render
    namespace['datatype']
  File "/home/zuul/src/opendev.org/openstack/watcher/.tox/py36/lib/python3.6/site-packages/wsme/rest/json.py", line 296, in encode_result
    return json.dumps(jsondata)
  File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'Decimal' is not JSON serializable

licanwei (li-canwei2) on 2020-04-17
Changed in watcher:
assignee: nobody → licanwei (li-canwei2)

Reviewed: https://review.opendev.org/720366
Committed: https://git.openstack.org/cgit/openstack/watcher/commit/?id=38649b2df087633c020803434e436bac0d782de8
Submitter: Zuul
Branch: master

commit 38649b2df087633c020803434e436bac0d782de8
Author: licanwei <email address hidden>
Date: Thu Apr 16 14:51:27 2020 +0800

    convert EfficacyIndicator.value to float type

    EfficacyIndicator.value is Decimal type, it's
    not JSON serializable. So we convert value type
    before serialization.

    Closed-Bug: #1873377
    Change-Id: Id38969775c446bece71f7a85c5c5d3efee9befa0

Dantali0n (dantalion) on 2020-05-11
Changed in watcher:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers