Skip to content

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

@dairiki

Description

@dairiki

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions