Opened 12 years ago

Closed 9 years ago

#12752 closed New feature (fixed)

validators should allow check against empty to be customized

Reported by: Shaun Cutts Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-alpha
Severity: Normal Keywords:
Cc: shaun@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a custom field, which sets up a correspondence between a numpy array and a postgres array. It mostly seems to be working. However, when I call .full_clean() on a model containing such a field, the validation code eventually calls:

207  ->	        if not self.blank and value in validators.EMPTY_VALUES:
208  	            raise exceptions.ValidationError(self.error_messages['blank'])

Here, the numpy definition for equality snarls things, and I get:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I suggest a django.db.models.Field member is_empty be added, which does value in validators.EMPTY_VALUES by default, but can be overridden by a custom subclass.

Change History (6)

comment:1 Changed 12 years ago by Alex Gaynor

Triage Stage: UnreviewedAccepted

comment:2 Changed 11 years ago by Matt McClanahan

Severity: Normal
Type: New feature

comment:3 Changed 10 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 10 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 9 years ago by Claude Paroz

From [22be90dd171dee], empty_values is now a field attribute, and is customizable.
Is this sufficient to resolve your use case, or do you really need a custom method to achieve what you want?

comment:6 Changed 9 years ago by Claude Paroz

Resolution: fixed
Status: newclosed

Assuming this is fixed.

Note: See TracTickets for help on using tickets.
Back to Top