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

Improves create_schema to get types from custom_fields #873

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lucasrcezimbra
Copy link

@lucasrcezimbra lucasrcezimbra commented Oct 11, 2023

Related to #335, #694, #764

Removes the need to update TYPES for fields passed as custom_fields.

Example:

class CustomField(models.fields.Field):
    pass

class TestModel(models.Model):
    custom = CustomField()

CustomType = TypeVar("CustomType")

# before
TYPES.update({'CustomField': CustomType})
Schema1 = create_schema(TestModel, custom_fields=[("custom", CustomType, ...)])

# with this PR
Schema1 = create_schema(TestModel, custom_fields=[("custom", CustomType, ...)])

@vitalik
Copy link
Owner

vitalik commented Oct 11, 2023

Hi @lucasrcezimbra

Thank you for PR

Maybe it's also make sense to add some builtin method like "register_field_type("CustomField", MyPydanticType) that will update TYPES

and then error message should suggest to use this function ?

@lucasrcezimbra
Copy link
Author

Maybe it's also make sense to add some builtin method like "register_field_type("CustomField", MyPydanticType) that will update TYPES

and then error message should suggest to use this function ?

Makes sense. I'll add it to this PR.

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 this pull request may close these issues.

None yet

2 participants