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

The allow_null parameter is not passed in rest framework SchemaField #69

Closed
noamkush opened this issue Jul 3, 2024 · 1 comment · Fixed by #70
Closed

The allow_null parameter is not passed in rest framework SchemaField #69

noamkush opened this issue Jul 3, 2024 · 1 comment · Fixed by #70

Comments

@noamkush
Copy link

noamkush commented Jul 3, 2024

When using allow_null with rest framework SchemaField, the implementation does not pass the parameter to the base class so we get the default which it False. The fix is simple but I was wondering whether I'm missing something here. Here's a reproduction:

from django_pydantic_field.rest_framework import SchemaField
from rest_framework import serializers
import pydantic


class Foo(pydantic.BaseModel):
    slug: str = "foo_bar"


class MySerializer(serializers.Serializer):
    foo_field = SchemaField(schema=Foo, allow_null=True)


serializer = MySerializer(data={"foo_field": None})
serializer.is_valid(raise_exception=True)

This gives:

ValidationError: {'foo_field': [ErrorDetail(string='This field may not be null.', code='null')]}
@surenkov
Copy link
Owner

surenkov commented Jul 8, 2024

Hey @noamkush

I prepared a small fix in #70, will release a patch to PyPI later today.
Thank you for reporting this issue!

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.

2 participants