Opened 6 years ago

Closed 3 years ago

#12752 closed New feature (fixed)

validators should allow check against empty to be customized

Reported by: shauncutts 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 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by mattmcc

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 3 years ago by claudep

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 3 years ago by claudep

  • Resolution set to fixed
  • Status changed from new to closed

Assuming this is fixed.

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