Code

#20179 closed Cleanup/optimization (invalid)

Proposal: Execute run_validators of the field in pre_save

Reported by: vini.gracindo@… Owned by: Vinnicyus Gracindo
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords: models, validators
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My proposal is execute the function run_validators in pre_save of a model. Actually, the framework execute this routine in the clean function.

When we created a validators, we hope with the validator is executed. If we create an object through the curl, via webservice or shell the validators are not executed.

Example:

class MyObject(models.Model):
    field = models.FloatField(validators = [MinValueValidator(0.0), MaxValueValidator(5.0)])

Shell:

MyObject.objects.create(field=6.0) #No validation happens.

Actually, the validation occur only in frontend.

Attachments (0)

Change History (2)

comment:1 Changed 13 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This is a case of "as designed, for historical reasons". When we introduced model validators, it wasn't possible to introduce them during model pre-save *and* maintain backwards compatibility in code.

Procedurally, I'm marking this as invalid because of the development history involved.

However, this is a complex issue, and one where in an ideal world, we *would* be doing what you suggest. If you're interested in pursuing this further, you should start a discussion on django-dev; in particular, focussing on how we could introduce this change in a manner that would minimize the impact on existing code.

comment:2 Changed 13 months ago by russellm

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

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.