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

[BUG] models.URLField serialized & validated as str #1157

Open
mpeyfuss opened this issue May 9, 2024 · 1 comment · May be fixed by #1255
Open

[BUG] models.URLField serialized & validated as str #1157

mpeyfuss opened this issue May 9, 2024 · 1 comment · May be fixed by #1255

Comments

@mpeyfuss
Copy link

mpeyfuss commented May 9, 2024

Describe the bug
When using a URLField in a Django model and then using a ModelSchema for serialization/validation on a POST request, the url is just validated as a str. Most other fields are covered in Ninja, but this one seems to be missing.

Versions (please complete the following information):

  • Python version: [e.g. 3.6] 3.11.9
  • Django version: [e.g. 4.0] 5.0
  • Django-Ninja version: [e.g. 0.16.2] 1.1.0
  • Pydantic version: [e.g. 1.9.0] 2.7.1
@pmdevita
Copy link

pmdevita commented May 16, 2024

It could be easy enough to just the annotation to the TYPES list in fields but the tricky bit is mimicking Django validator behavior. Django's default behavior is debatable too though, as it will accept FTP URLs and IPs which many people might not want.

Maybe the more complete solution is to be able to declare a Pydantic type annotation on a custom Django Field, then it could get reused automatically everywhere. It would also provide a path for third-party libraries that implement their own fields to improve their out-of-box support with Ninja.

lapinvert added a commit to lapinvert/django-ninja that referenced this issue Aug 5, 2024
@lapinvert lapinvert linked a pull request Aug 5, 2024 that will close this issue
lapinvert added a commit to lapinvert/django-ninja that referenced this issue Aug 5, 2024
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