Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24373 closed Uncategorized (fixed)

RegexValidator In ArrayField Not Running

Reported by: David Muller Owned by: Marc Tamlyn <marc.tamlyn@…>
Component: contrib.postgres Version: 1.8alpha1
Severity: Normal Keywords: ArrayField RegexValidator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying out Django 1.8's new ArrayField and was hoping to enforce RegexValidation on an array of CharFields. It appears, however, that the RegexValidator is not being run.

For the sake of simplicity, let's say I only wanted to accept numeric values in my CharFields. We'll also say that my save() method calls full_clean():

class TestModel(models.Model):
    names = ArrayField(
        models.CharField(max_length=100, blank=False, validators=[RegexValidator(r'^[0-9]*$')]),
    )

    def save(self, *args, **kwargs):
        """
        Raise ValidationError if a field doesn't pass validation.
        """
        try:
            self.full_clean()
        except ValidationError:
            raise
        super(TestModel, self).save(*args, **kwargs)

No ValidationError is thrown, a TestModel record is created successfully:

In [2]: TestModel.objects.create(names=['no'])
Out[2]: <TestModel: TestModel object>

Is not possible to add validators to the <base_field> of my ArrayField?

Thanks!

Change History (2)

comment:1 by Marc Tamlyn <marc.tamlyn@…>, 10 years ago

Owner: set to Marc Tamlyn <marc.tamlyn@…>
Resolution: fixed
Status: newclosed

In c490e410af086fa89f40d515505bba02a08168f3:

Fixed #24373 -- Added run_validators to ArrayField.

Thanks to DavidMuller for the report.

comment:2 by Marc Tamlyn <marc.tamlyn@…>, 10 years ago

In b6ef67d752cab200028c39c31c602dd6696b69ce:

[1.8.x] Fixed #24373 -- Added run_validators to ArrayField.

Thanks to DavidMuller for the report.

Backport of c490e410af from master

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