Code

Opened 4 years ago

Closed 13 months 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

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.

Attachments (0)

Change History (6)

comment:1 Changed 4 years ago by Alex

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

comment:2 Changed 3 years ago by mattmcc

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 13 months 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 13 months ago by claudep

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

Assuming this is fixed.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.