[Django] #25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops indexes

38 views
Skip to first unread message

Django

unread,
Jul 27, 2015, 9:11:04 AM7/27/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
----------------------------------+-----------------
Reporter: fabianbuechler | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+-----------------
I believe I bumped into a bug using the new PostgreSQL `ArrayField` from
1.8 in combination with `db_index=True`:


This seems to be related to Django ticket #12234 which introduced creating
secondary
`varchar_patterns_ops` or `text_patterns_ops` indexes for varchar or text
fields
respectively, so that PostgreSQL could use them for the `contains` filter
(e.g. `MyModel.object.filter(name__contains='abc')`).

However, for the array fields introduced with Django 1.8 this does not
seem to
work when having `db_index` activated. When `syncdb` or `migrate` try to
create the secondary index, PostgreSQL raises an error like this:

{{{#!python
django.db.utils.ProgrammingError: operator class "varchar_pattern_ops"
does not accept data type character varying[]
}}}

The executed SQL statement is something like this:

{{{#!sql
CREATE INDEX "shop_product_package_product_numbers_2ebd72fe1541fbd4_like"
ON "shop_product" ("package_product_numbers" varchar_pattern_ops)
}}}

The important parts of the model defintion are:

{{{#!python
class Product(models.Model):

package_product_numbers = ArrayField(
models.CharField(max_length=10, blank=True),
verbose_name="Package product numbers",
null=True, default=None, db_index=True)
}}}

I'm currently using a workaroud to fix this. I created a custom DB backend
that inherits from the postgresql_psycopg2 one and overwrites the
`DatabaseCreation.sql_indexes_for_field` and
`DatabaseSchemaEditor._model_indexes_sql` methods to check for ArrayFields
when creating those secondary indexes. I can post this code here, if you
need it, however, I don't think that this is the right solution, since the
PostgreSQL database backend should not really need to know anything about
the `django.contrib.postgresql` stuff.

Please let me know if I can help to reproduce this.

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

Django

unread,
Jul 28, 2015, 1:15:49 PM7/28/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
----------------------------------+------------------------------------

Reporter: fabianbuechler | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


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

Django

unread,
Aug 4, 2015, 11:51:53 PM8/4/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
----------------------------------+--------------------------------------
Reporter: fabianbuechler | Owner: caioariede
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* owner: => caioariede
* status: new => assigned


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

Django

unread,
Aug 7, 2015, 2:56:02 PM8/7/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
----------------------------------+--------------------------------------
Reporter: fabianbuechler | Owner: caioariede
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 1.8

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by caioariede):

Seems to happen only when the table is created. Adding the field later
does not trigger the error.

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

Django

unread,
Aug 8, 2015, 8:46:08 AM8/8/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
----------------------------------+--------------------------------------
Reporter: fabianbuechler | Owner: caioariede
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 1.8

Severity: Normal | 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 caioariede):

* has_patch: 0 => 1


Comment:

Pull request: https://github.com/django/django/pull/5118

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

Django

unread,
Aug 14, 2015, 7:42:58 AM8/14/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
-------------------------------------+-------------------------------------

Reporter: fabianbuechler | Owner:
| caioariede
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* stage: Accepted => Ready for checkin


Comment:

Pending a few cosmetic edits.

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

Django

unread,
Aug 15, 2015, 10:02:48 AM8/15/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
-------------------------------------+-------------------------------------
Reporter: fabianbuechler | Owner:
| caioariede
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"dad8434d6ff5da10959672726dc9b397296d380b" dad8434]:
{{{
#!CommitTicketReference repository=""
revision="dad8434d6ff5da10959672726dc9b397296d380b"
Fixed #25180 -- Prevented varchar_patterns_ops and text_patterns_ops
indexes for ArrayField.
}}}

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

Django

unread,
Aug 15, 2015, 10:12:00 AM8/15/15
to django-...@googlegroups.com
#25180: ArrayFields should not have varchar_patterns_ops or text_patterns_ops
indexes
-------------------------------------+-------------------------------------
Reporter: fabianbuechler | Owner:
| caioariede
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"29fa1b5800f2b86b9860dac38377e95f7c36063f" 29fa1b58]:
{{{
#!CommitTicketReference repository=""
revision="29fa1b5800f2b86b9860dac38377e95f7c36063f"
[1.8.x] Fixed #25180 -- Prevented varchar_patterns_ops and
text_patterns_ops indexes for ArrayField.

Backport of dad8434d6ff5da10959672726dc9b397296d380b from master
}}}

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

Reply all
Reply to author
Forward
0 new messages