From 49984b06dcf373d3d4810d271c89e91199a2d44f Mon Sep 17 00:00:00 2001 From: Andrew Pinkham Date: Sat, 22 Dec 2018 14:16:20 +0100 Subject: [PATCH] Regression test for issue 6341 Ensures that the UniqueFor[Date,Month,Year]Validator classes do not raise errors when a serializer is partially updated without the fields with the uniqueness constraint. --- tests/test_validators.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_validators.py b/tests/test_validators.py index 4bbddb64b..6ffb7167f 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -582,6 +582,13 @@ class ValidatorsTests(TestCase): with pytest.raises(ValidationError): validator.enforce_required_fields(attrs) + def test_validator_passes_with_instance(self): + validator = BaseUniqueForValidator(queryset=object(), field='foo', + date_field='bar') + validator.instance = object() + + assert validator.enforce_required_fields({}) is None + def test_validator_raises_error_when_abstract_method_called(self): validator = BaseUniqueForValidator(queryset=object(), field='foo', date_field='bar')