🐛(backend) Fix unreachable exception handler for URLValidator

The exception block was never being executed because URLValidator raises
django.core.exceptions.ValidationError, not
drf.exceptions.ValidationError, so the except block was dead code.


Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
This commit is contained in:
Mohamed El Amine BOUKERFA 2026-04-10 14:21:56 +01:00 committed by GitHub
parent d0bf24f368
commit 1ebdda8c9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -2135,7 +2135,7 @@ class DocumentViewSet(
url_validator = URLValidator(schemes=["http", "https"])
try:
url_validator(url)
except drf.exceptions.ValidationError as e:
except ValidationError as e:
return drf.response.Response(
{"detail": str(e)},
status=drf.status.HTTP_400_BAD_REQUEST,

View file

@ -255,7 +255,7 @@ def test_api_docs_cors_proxy_invalid_url(url_to_fetch):
f"/api/v1.0/documents/{document.id!s}/cors-proxy/?url={url_to_fetch}"
)
assert response.status_code == 400
assert response.json() == ["Enter a valid URL."]
assert response.json() == {"detail": "['Enter a valid URL.']"}
@unittest.mock.patch("core.api.viewsets.socket.getaddrinfo")