subscriptions create failed due to Object of type 'bytes' is not JSON serializable

Bug #1966401 reported by Xing Zhang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zaqar
Fix Released
Undecided
Xing Zhang

Bug Description

When creating subscriptions in queues, zaqar server raise an error: TypeError: Object of type 'bytes' is not JSON serializable

the response_body has bytes value like this, the value of source is bytes type:
{'subscriptions': [{'id': '20fce66f-eed0-4d52-9a57-25fca7c2b349', 'source': b'351465', 'subscriber': b'mailto:<email address hidden>', 'ttl': 3155673600, 'age': 1870, 'options': {'subject': '<email address hidden>'}, 'confirmed': True}], 'links': [{'rel': 'next', 'href': '/v2/queues/351465/subscriptions?marker=20fce66f-eed0-4d52-9a57-25fca7c2b349'}]}

Most projects are update json module to jsonutils of oslo.serialization, consider to update in zaqar:
https://review.opendev.org/q/Update+json+module+to+jsonutils+status:merged

Full trace is:
Failed to send email because a bytes-like object is required, not 'str'.: TypeError: a bytes-like object is required, not 'str'
 Traceback (most recent call last):
   File "/usr/lib/python3.6/site-packages/zaqar/notification/tasks/mailto.py", line 103, in execute
     p.communicate(msg.as_string())
   File "/usr/lib64/python3.6/subprocess.py", line 848, in communicate
     self._stdin_write(input)
   File "/usr/lib64/python3.6/subprocess.py", line 801, in _stdin_write
     self.stdin.write(input)
 zaqar.notification.tasks.mailto TypeError: a bytes-like object is required, not 'str'
 zaqar.notification.tasks.mailto

Object of type 'bytes' is not JSON serializable: TypeError: Object of type 'bytes' is not JSON serializable
 Traceback (most recent call last):
   File "falcon/api.py", line 269, in falcon.api.API.__call__
   File "/usr/lib/python3.6/site-packages/zaqar/common/decorators.py", line 48, in wrapper
     return func(*args, **kwargs)
   File "/usr/lib/python3.6/site-packages/zaqar/transport/acl.py", line 48, in handler
     return func(*args, **kwargs)
   File "/usr/lib/python3.6/site-packages/zaqar/transport/wsgi/v2_0/subscriptions.py", line 171, in on_get
     resp.body = utils.to_json(response_body)
   File "/usr/lib/python3.6/site-packages/zaqar/transport/utils.py", line 63, in to_json
     return json.dumps(obj, ensure_ascii=False)
   File "/usr/lib64/python3.6/json/__init__.py", line 238, in dumps
     **kw).encode(obj)
   File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
     chunks = self.iterencode(o, _one_shot=True)
   File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
     return _iterencode(o, 0)
   File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
     o.__class__.__name__)
 zaqar.transport.wsgi.driver TypeError: Object of type 'bytes' is not JSON serializable

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to zaqar (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/zaqar/+/835380

Changed in zaqar:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to zaqar (master)

Reviewed: https://review.opendev.org/c/openstack/zaqar/+/835380
Committed: https://opendev.org/openstack/zaqar/commit/2abe46ae21fe0fa83587328ffb2f44075d3a44fc
Submitter: "Zuul (22348)"
Branch: master

commit 2abe46ae21fe0fa83587328ffb2f44075d3a44fc
Author: Xing Zhang <email address hidden>
Date: Sun Mar 27 13:54:52 2022 +0800

    Update json module to jsonutils

    oslo project provide jsonutils, the others project use it
    this PS to update the json moudule to oslo jsonutils.

    Closes-bug: #1966401
    Change-Id: I9cbe9f03c32e4f42822def727aa2871d502641f4

Changed in zaqar:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to zaqar (stable/wallaby)

Fix proposed to branch: stable/wallaby
Review: https://review.opendev.org/c/openstack/zaqar/+/835495

Xing Zhang (xingzhang)
Changed in zaqar:
assignee: nobody → Xing Zhang (xingzhang)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/zaqar 15.0.0.0rc1

This issue was fixed in the openstack/zaqar 15.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.