-
Notifications
You must be signed in to change notification settings - Fork 6
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
Allow related fields to be nullable #7
Allow related fields to be nullable #7
Conversation
@@ -102,7 +102,16 @@ def ModelSchemaField(field: Any, schema_name: str) -> tuple: | |||
description = None | |||
title = None | |||
max_length = None | |||
python_type = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, was unused
@@ -102,7 +102,16 @@ def ModelSchemaField(field: Any, schema_name: str) -> tuple: | |||
description = None | |||
title = None | |||
max_length = None | |||
python_type = None | |||
|
|||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this up here so it can be used for any field (related, or not)
@@ -172,6 +173,8 @@ def get(self, key: Any, default: Any = None) -> Any: | |||
attr = list(attr.all()) | |||
elif outer_type_ == int and issubclass(type(attr), Model): | |||
attr = attr.id | |||
elif inspect.isclass(type(attr)) and issubclass(type(attr), Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the nullable related field change: the tests/test_fields.py::test_enum_choices
test was failing (even on main
branch. This should fix that.
Test fail:
FAILED tests/test_fields.py::test_enum_choices - pydantic_core._pydantic_core.ValidationError: 2 validation errors for PreferenceSchema
preferred_food
Input should be 'ba' or 'ap' [type=enum, input_value=<FoodChoices.BANANA: 'ba'>, input_type=FoodChoices]
For further information visit https://errors.pydantic.dev/2.7/v/enum
preferred_group
Input should be 1 or 2 [type=enum, input_value=<GroupChoices.GROUP_1: 1>, input_type=GroupChoices]
For further information visit https://errors.pydantic.dev/2.7/v/enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
@@ -281,3 +281,4 @@ class Case(ExtendedModel): | |||
|
|||
class Listing(models.Model): | |||
items = ArrayField(models.TextField(), size=4) | |||
content_type = models.ForeignKey(ContentType, on_delete=models.PROTECT, blank=True, null=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows us to test that blank
/null
flags are honored.
@jonathan-s this is ready for review please |
7c060e0
to
4f0b574
Compare
Thank you for the PR, and I also appreciate that you took the time to comment some parts in the PR. |
Thanks for the fast merge @jonathan-s , will you cut a pypi release soon? |
blank
ornull
kwargs and addingUnion[type, None]
myvar.value
instead of the enum itself