Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30328 closed Bug (fixed)

Integer field range validators crash when limit_value is callable.

Reported by: Harro Owned by: Scott Fitsimones
Component: Database layer (models, ORM) Version: 2.2
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description (last modified by Harro)

in #29860 for django 2.2 the option was added to pass in a callable.

I just upgraded to django 2.2 and found our custom max value validator for current year + 1 (which gave us a migration on the year change) and thought to replace it with the new mechanic.

The result was the following error:

  File "<venv>/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1799, in <genexpr>
validator.limit_value <= max_value for validator in validators_)):

So the field wants to check that the validator's max (and min) value lie within range of the Integer field which is not possible with the callable.

The fix should be simple: Check if it's a callable and call it for the value.

Change History (9)

comment:1 by Harro, 6 years ago

Description: modified (diff)

comment:2 by Harro, 6 years ago

Description: modified (diff)

comment:3 by Harro, 6 years ago

Should add that it only fails if the database backend has limits (sqlite does not)

comment:4 by Mariusz Felisiak, 6 years ago

Severity: NormalRelease blocker
Summary: Callable passed to Min/Max validators breaks in the fieldsInteger field range validators crash when limit_value is callable.
Triage Stage: UnreviewedAccepted

Reproduced at 1ffddfc233e2d5139cc6ec31a4ec6ef70b10f87f.

Regression in 24cae0bedc51093b363c323af555946a8edea1a1.

Thanks for the report!

comment:5 by Scott Fitsimones, 6 years ago

Owner: changed from nobody to Scott Fitsimones
Status: newassigned

comment:6 by Scott Fitsimones, 6 years ago

Has patch: set

comment:7 by Mariusz Felisiak, 6 years ago

Needs tests: set
Patch needs improvement: set

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In a14c0fd:

Fixed #30328 -- Fixed crash of IntegerField.validators when limit_value in a custom validator is callable.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

In 95811c3d:

[2.2.x] Fixed #30328 -- Fixed crash of IntegerField.validators when limit_value in a custom validator is callable.

Backport of a14c0fda15db7e0eb982ac7b68d47b45fc95b4cb from master

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