Closed brakhane closed 5 years ago
This took really long to find, because of #1155 masking the real error, BTW. It would be nice if an exception during serialization wouldn't fail with a confusing message on Python3.
Here's the line in trio that adds a guard object into locals: https://github.com/python-trio/trio/blob/79d66647c3c947f614b51f607be6fd527df6777f/trio/_core/_run.py#L1245
Trio uses an ugly hack and puts a value into locals with a non string key (class LOCALS_KI_PROTECTION_ENABLED).
When trying to serialize that, JsonEncoder crashes. So we ensure that every key is indeed a string.
Another way to solve this problem would be to pass skipkeys=True to json.dumps, but this might mask other errors.