Opened 12 years ago

Closed 12 years ago

#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.

Change History (2)

comment:1 by Russell Keith-Magee, 12 years ago

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 by Russell Keith-Magee, 12 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top