Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Ensure that all keys in locals are strings before serializing #1273

Closed
wants to merge 1 commit into from
Closed

Ensure that all keys in locals are strings before serializing #1273

wants to merge 1 commit into from

Conversation

brakhane
Copy link

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.

@brakhane
Copy link
Author

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.
@brakhane brakhane closed this Feb 6, 2019
@brakhane brakhane deleted the string-key-fix branch February 6, 2019 20:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant