fedora-infra/fedmsg

Python 3 incompatibility when signing

Closed this issue · 4 comments

After switching to python 3, my code started to crash with:

  File "/usr/lib/python3.6/site-packages/koschei/plugins/fedmsg_plugin/backend/publisher.py", line 31, in publish_fedmsg
    fedmsg.publish(**message)
  File "/usr/lib/python3.6/site-packages/fedmsg/__init__.py", line 81, in _wrapper
    return func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/fedmsg/__init__.py", line 93, in publish
    return __local.__context.publish(topic, msg, **kw)
  File "/usr/lib/python3.6/site-packages/fedmsg/core.py", line 328, in publish
    [topic, fedmsg.encoding.dumps(msg).encode('utf-8')],
  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/lib/python3.6/site-packages/fedmsg/encoding/__init__.py", line 73, in default
    return super(FedMsgEncoder, self).default(obj)
  File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

There are no bytes in my message, so I tried to run it with a debugger and print the message right before it fails (long values replaced by ....):

{'certificate': b'....',
 'crypto': 'x509',
 'i': 1,
 'msg': {'collection': 'f27',
  'collection_name': 'Fedora Rawhide',
  'groups': [],
  'koji_instance': 'primary',
  'name': 'net-snmp',
  'new': 'failing',
  'old': 'ok',
  'repo': 'f27'},
 'msg_id': '2017-065efb41-59ac-4285-abb5-8d7d91e9f260',
 'signature': b'....',
 'timestamp': 1512397293,
 'topic': 'org.fedoraproject.stg.koschei.package.state.change',
 'username': 'koschei'}

As you can see, the certificate and signature keys are of type bytes, which makes the json encoder fail.

fedmsg version: fedmsg-1.0.1-4.fc27.noarch

CC @mizdebsk

Could you, please, make a release with this fix? It's blocking us from migrating Koschei to Python 3

Sorry, it got lost in the shuffle. I've tagged a release and it's on PyPI. Fedora builds are going now.

When can we expect it in stable (and thus in infra)?

I was just waiting for some additional testing, thanks for doing that! I've submitted it for the next batch update, so Wednesday. If you need it sooner you could always tag it into f27-infra as well.