Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

field_for_schema can use _RECURSION_GUARD.seen_classes before it is initialized #229

Open
dairiki opened this issue Jan 12, 2023 · 0 comments · May be fixed by #214
Open

field_for_schema can use _RECURSION_GUARD.seen_classes before it is initialized #229

dairiki opened this issue Jan 12, 2023 · 0 comments · May be fixed by #214

Comments

@dairiki
Copy link
Collaborator

dairiki commented Jan 12, 2023

Currently, while computing schemas for dataclasses, we keep some thread-local context in _RECURSION_GUARD.seen_classes.

The field_for_schema function does not manage the thread-locals in _RECURSION_GUARD, yet it can (attempt to) use them if called for a type that is or includes a dataclass (or other exotic types). This can cause an exception if field_for_schema is called before the first call to class_schema.

from marshmallow_dataclass import field_for_schema

class A:
    x: int

field_for_schema(A) # => AttributeError("'_thread__local' object has not attribute 'seen_classes'")

This bug is fixed by #214 (currently a work-in-progress).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant