#741 protonmsg fails on common data types
Closed: Fixed Opened by mikem.

The protonmsg hooks into callbacks and emits their data as json. However, the data provided to callbacks is not guaranteed to be json serializable.

Example error:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/koji/plugin.py", line 191, in run_callbacks
    func(cbtype, *cb_args, **cb_kwargs)
  File "/usr/lib/koji-hub-plugins/protonmsg.py", line 240, in prep_repo_init
    queue_msg(address, props, kws)
  File "/usr/lib/koji-hub-plugins/protonmsg.py", line 138, in queue_msg
    body = json.dumps(data)
  File "/usr/lib64/python2.7/json/__init__.py", line 244, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: set(['x86_64', 'i386']) is not JSON serializable

The plugin should pass a default handler to json.dumps to handle types that the json encoder cannot. It would be better to slightly munge or omit some of this data than to fail the call.

PR #768
a) Are there any other suspected data types which can make it there?
b) Maybe put some json_extended_dumps helper function to koji/init.py for usage in code?

Metadata Update from @tkopecek:
- Issue set to the milestone: 1.16

Are there any other suspected data types which can make it there?

I think for safety reasons I'd like to exclude or squash anything that not json cannot encode. As I wrote before, "It would be better to slightly munge or omit some of this data than to fail the call".

Commit dad74a3a fixes this issue

Commit 3bfcc6a6 fixes this issue

This issue has been migrated to Fedora Forge:
https://forge.fedoraproject.org/koji/koji/issues/741

Please continue any further discussion there.

Metadata