Skip to content

Commit 933eb5b

Browse files
committed
Check for requires_context = True when calling validators
In encode/django-rest-framework#7062 the API for calling DRF validators changed to require the caller to inspect the validator instance to determine if the validator requires a second argument at call time. Usage with DRF >=3.11.0 requires this support.
1 parent a2b0978 commit 933eb5b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rest_framework_friendly_errors/mixins.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ def _run_validator(self, validator, field, message, parent=None):
178178
if parent:
179179
initial_data = self.initial_data[parent.field_name]
180180
for data in initial_data:
181-
validator(data[field.field_name])
181+
if getattr(validator, 'requires_context', False):
182+
validator(data[field.field_name], field)
183+
else:
184+
validator(data[field.field_name])
182185
else:
183-
validator(self.initial_data[field.field_name])
186+
if getattr(validator, 'requires_context', False):
187+
validator(self.initial_data[field.field_name], field)
188+
else:
189+
validator(self.initial_data[field.field_name])
184190
except (DjangoValidationError, RestValidationError) as err:
185191
err_message = err.detail[0] \
186192
if hasattr(err, 'detail') else err.message

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy