diff --git a/drf_writable_nested/mixins.py b/drf_writable_nested/mixins.py index 134ae7e..34d26f3 100644 --- a/drf_writable_nested/mixins.py +++ b/drf_writable_nested/mixins.py @@ -400,10 +400,13 @@ def get_fields(self): def _validate_unique_fields(self, validated_data): for field_name in self._unique_fields: unique_validator = UniqueValidator(self.Meta.model.objects.all()) - unique_validator.set_context(self.fields[field_name]) - try: - unique_validator(validated_data[field_name]) + # `set_context` removed on DRF >= 3.11, pass in via __call__ instead + if hasattr(unique_validator, 'set_context'): + unique_validator.set_context(self.fields[field_name]) + unique_validator(validated_data[field_name]) + else: + unique_validator(validated_data[field_name], self.fields[field_name]) except ValidationError as exc: raise ValidationError({field_name: exc.detail})