Skip to content

Handle custom field validation errors without validate methods#19

Open
gaoflow wants to merge 1 commit into
FutureMind:masterfrom
gaoflow:fix-8-custom-field-validation-error
Open

Handle custom field validation errors without validate methods#19
gaoflow wants to merge 1 commit into
FutureMind:masterfrom
gaoflow:fix-8-custom-field-validation-error

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 27, 2026

Copy link
Copy Markdown

Summary

  • guard lookup of serializer-level validate_ methods when classifying field errors
  • keep existing fallback behavior for unknown custom field errors instead of raising AttributeError
  • add a regression test for ValidationError raised from a custom Field.to_internal_value()

Fixes #8.

Tests

  • uv run --python 3.10 --with 'django<3' --with 'djangorestframework<3.12' --with pytest --with pytest-django --with six --with-editable . pytest tests/test_serializers.py::SerializerErrorsTestCase::test_custom_field_validation_error_without_validate_method -q
  • uv run --python 3.10 --with 'django<3' --with 'djangorestframework<3.12' --with pytest --with pytest-django --with six --with-editable . pytest tests/test_serializers.py -q
  • uv run --python 3.10 --with 'django<3' --with 'djangorestframework<3.12' --with pytest --with pytest-django --with six --with 'flake8==2.4.0' --with 'pep8==1.5.7' --with-editable . python runtests.py --lintonly
  • git diff --check

Note: I also tried the full test suite. With Django 2 it fails during collection because the existing tests import django.core.urlresolvers. With Django 1.11 and older DRF on Python 3.9 it collects but has existing ModelSerializer compatibility failures unrelated to this change.

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 this pull request may close these issues.

Crash when raising ValidationError in a custom field's to_internal_value()

1 participant