[Django] #30328: Callable passed to Min/Max validators breaks in the fields

14 views
Skip to first unread message

Django

unread,
Apr 4, 2019, 5:01:24 AM4/4/19
to django-...@googlegroups.com
#30328: Callable passed to Min/Max validators breaks in the fields
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/30328>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 4, 2019, 5:02:26 AM4/4/19
to django-...@googlegroups.com
#30328: Callable passed to Min/Max validators breaks in the fields
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Harro:

Old description:

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

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:1>

Django

unread,
Apr 4, 2019, 5:03:06 AM4/4/19
to django-...@googlegroups.com
#30328: Callable passed to Min/Max validators breaks in the fields
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Harro:

Old description:

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

New description:

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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:2>

Django

unread,
Apr 4, 2019, 5:44:17 AM4/4/19
to django-...@googlegroups.com
#30328: Callable passed to Min/Max validators breaks in the fields
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Harro):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:3>

Django

unread,
Apr 4, 2019, 5:52:37 AM4/4/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.

-------------------------------------+-------------------------------------
Reporter: Harro | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Unreviewed => Accepted
* severity: Normal => Release blocker


Comment:

Reproduced at 1ffddfc233e2d5139cc6ec31a4ec6ef70b10f87f.

Regression in 24cae0bedc51093b363c323af555946a8edea1a1.

Thanks for the report!

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:4>

Django

unread,
Apr 5, 2019, 10:14:51 PM4/5/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: scottfits
Type: Bug | Status: assigned

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by scottfits):

* owner: nobody => scottfits
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:5>

Django

unread,
Apr 6, 2019, 1:15:49 AM4/6/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: scottfits
Type: Bug | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by scottfits):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/11180 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:6>

Django

unread,
Apr 8, 2019, 2:14:47 AM4/8/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: Scott
| Fitsimones

Type: Bug | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:7>

Django

unread,
Apr 19, 2019, 2:21:57 AM4/19/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: Scott
| Fitsimones
Type: Bug | Status: closed

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"a14c0fda15db7e0eb982ac7b68d47b45fc95b4cb" a14c0fd]:
{{{
#!CommitTicketReference repository=""
revision="a14c0fda15db7e0eb982ac7b68d47b45fc95b4cb"
Fixed #30328 -- Fixed crash of IntegerField.validators when limit_value in
a custom validator is callable.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:8>

Django

unread,
Apr 19, 2019, 2:24:52 AM4/19/19
to django-...@googlegroups.com
#30328: Integer field range validators crash when limit_value is callable.
-------------------------------------+-------------------------------------
Reporter: Harro | Owner: Scott
| Fitsimones
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"95811c3de9334c313522982c3d125a8c2ff7ab72" 95811c3d]:
{{{
#!CommitTicketReference repository=""
revision="95811c3de9334c313522982c3d125a8c2ff7ab72"
[2.2.x] Fixed #30328 -- Fixed crash of IntegerField.validators when


limit_value in a custom validator is callable.

Backport of a14c0fda15db7e0eb982ac7b68d47b45fc95b4cb from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30328#comment:9>

Reply all
Reply to author
Forward
0 new messages