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

Different schema classes are generated per reference of the same data class #270

Open
jmgoncalves opened this issue Jun 30, 2023 · 0 comments

Comments

@jmgoncalves
Copy link

jmgoncalves commented Jun 30, 2023

from dataclasses import dataclass
import desert

@dataclass
class A:
    some_string: str

@dataclass
class B:
    prop_one: A
    prop_two: A

if __name__ == "__main__":
    schema = desert.schema_class(B)()
    prop_one_schema = schema.fields["prop_one"].schema
    prop_two_schema = schema.fields["prop_two"].schema
    print(isinstance(prop_one_schema, prop_one_schema.__class__)) # True
    print(isinstance(prop_one_schema, prop_two_schema.__class__)) # False
    print(isinstance(prop_two_schema, prop_one_schema.__class__)) # False
    print(isinstance(prop_two_schema, prop_two_schema.__class__)) # True

For the same class A there are as many schema classes as there are properties of type A.

This is inefficient (uses up more memory than needed) and can cause problems with other libraries, such as https://github.com/marshmallow-code/apispec which uses the schema class and modifiers to determine schema equality.

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

No branches or pull requests

1 participant