Closed
Description
Initially encountered in our
- Local runtime schema serialization endpoints dandi/dandi-archive#2386
where our response model containsschema_url
which is aURLField
and when we plugged in a "proper" URL to local test instancehttp://testserver/api/schema/latest/dandiset/
, then response we were getting from server became with code 400 and.content
saying
(Pdb) p resp.content
b'{"schema_url":["Enter a valid URL."]}'
with such minimal reproducer depicting the issue:
from rest_framework import serializers
class MySerializer(serializers.Serializer):
url = serializers.URLField()
def test_valid_url():
serializer = MySerializer(data={'url': 'http://testserver/path'})
serializer.is_valid()
running pytest on which would give you an ugly excepted demanding configuration since i18n would not yet be configured to give a proper localized error...
but replacing that simple hostname testserver
with a domain name with the TLD (e.g. testserver.com
), which is AFAIK is not required for a URL to be valid, pytest would pass just fine.
❯ sed -i -E 's,(testserver),\1.com,g' /tmp/tttt.py
❯ python -m pytest -s -v /tmp/tttt.py
====================================================================================================== test session starts =======================================================================================================
platform linux -- Python 3.11.12, pytest-8.3.5, pluggy-1.6.0 -- /home/yoh/proj/dandi/dandi-archive/.venv/bin/python
cachedir: .pytest_cache
django: version: 4.2.21
rootdir: /tmp
plugins: django-s3-file-field-1.0.1, Faker-37.3.0, mock-3.14.0, memray-1.7.0, factoryboy-2.7.0, django-4.11.1, cov-6.1.1
collected 1 item
../../../../../tmp/tttt.py::test_valid_url PASSED
So
- any way to workaround?
- if I got it right such validation stems from DJANGO itself, so should it be checked/fixed there?
Metadata
Metadata
Assignees
Labels
No labels