[Django] #30258: Failed to add CheckConstraint on IntegerRangeField

5 views
Skip to first unread message

Django

unread,
Mar 16, 2019, 6:19:11 AM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman | Owner: nobody
Koschnick |
Type: Bug | Status: new
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Adding a CheckConstraint like:

{{{
constraints = (
m.CheckConstraint(check=m.Q(precipitation_probability__contained_by=NumericRange(0,
101)), name='precipitation_percent_range'),
)
}}}

resulted in the following error (full traceback attached):

django.db.utils.ProgrammingError: syntax error at or near "object"
LINE 1: ...obability" <@ <psycopg2._range.NumberRangeAdapter object at ...

The attached patch fixes the issue for me.

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

Django

unread,
Mar 16, 2019, 6:19:42 AM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

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

* Attachment "exception" added.

traceback

Django

unread,
Mar 16, 2019, 6:19:57 AM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

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

* Attachment "schema.diff" added.

patch

Django

unread,
Mar 16, 2019, 1:49:21 PM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => assigned
* owner: nobody => Simon Charette
* version: master => 2.2
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 16, 2019, 2:10:03 PM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

Thanks for your report and patch, I turned it into a
[https://github.com/django/django/pull/11086 PR].

Happy to give you attribution if you can provide an email alias.

On a different subject this patch unveiled what I believe is a design flaw
with `Index` and `Constraint`'s `create_sql` and `remove_sql` methods.
They should return a tuple of SQL and a parms instead of a ''baked'' SQL
string so we can let the backend deal with the escaping itself. I'll spin
up a different PR that does just that.

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

Django

unread,
Mar 16, 2019, 4:28:11 PM3/16/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

I gave the `create_sql`/`constraint_sql` methods returning `(sql, params)`
[https://github.com/charettes/django/pull/new/constraint-index-sql a go]
but it would require a non-trivial refactor of `deferred_sql`. I still
think it would be worthy to make and might even be required in the future
to handle the quoting on backends that don't expose low level quoting
facilities like `psycopg2` does. The number of reports regarding similar
crashes now that `CheckConstraint`, `UniqueConstraint(condition)`, and
`Index(condition)` are out there will be good indicator of whether or not
this is required.

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

Django

unread,
Mar 18, 2019, 3:55:21 AM3/18/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Hey Simon, thanks for pulling this into the PR!

> I still think it would be worthy to make ...

Fancy creating a separate ticket (at your leisure)? 👍

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

Django

unread,
Mar 18, 2019, 4:31:25 AM3/18/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"386d89ab55e620440d30590a8a104fe6d5eef830" 386d89a]:
{{{
#!CommitTicketReference repository=""
revision="386d89ab55e620440d30590a8a104fe6d5eef830"
Fixed #30258 -- Adjusted postgres schema value quoting of ranges.

Thanks Tilman Koschnick for the report and patch.
}}}

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

Django

unread,
Mar 18, 2019, 4:33:19 AM3/18/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

In [changeset:"883d87074dd916224e2436ecc3dad8dd80e87c16" 883d870]:
{{{
#!CommitTicketReference repository=""
revision="883d87074dd916224e2436ecc3dad8dd80e87c16"
[2.2.x] Fixed #30258 -- Adjusted postgres schema value quoting of ranges.

Thanks Tilman Koschnick for the report and patch.

Backport of 386d89ab55e620440d30590a8a104fe6d5eef830 from master
}}}

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

Django

unread,
Mar 19, 2019, 3:15:06 AM3/19/19
to django-...@googlegroups.com
#30258: Failed to add CheckConstraint on IntegerRangeField
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: Simon
| Charette
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: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tilman Koschnick):

Hi, thanks for looking into this, and getting the fix into rc1!

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

Reply all
Reply to author
Forward
0 new messages