Opened 14 years ago

Closed 11 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

Description

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:

django.db.models.fields.init.py(207)validate():

206  	
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 by Alex Gaynor, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Matt McClanahan, 13 years ago

Severity: Normal
Type: New feature

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Claude Paroz, 11 years ago

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 by Claude Paroz, 11 years ago

Resolution: fixed
Status: newclosed

Assuming this is fixed.

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