Django

Code

Ticket #2422 (closed: invalid)

Opened 2 years ago

Last modified 1 year ago

unique_together on SQLite uses 'iexact' matching, I expected this to be 'exact'

Reported by: scanner@nominum.com Assigned to: adrian
Milestone: Component: Admin interface
Version: Keywords: SQlite
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I have a model that has:

    class Meta:
        unique_together = (('gecko_engine_instance', 'name'), ('gecko_engine_instance', 'dhcp_client_identifier'), )

For the 'dhcp_client_identifier' "foo" is different from "Foo."

However the query that was enforcing uniqueness ends up looking line:

SELECT "dcs_client"."id" ... blah blah ..  WHERE ("dcs_client__gecko_engine_instance"."id" ILIKE '1' AND  dcs_client"."dhcp_client_identifier" ILIKE 'blarg')

which will fail if I have another client object with a dhcp_client_identifier of 'Blarg.' I figure there must be a reason for this although it causes me problems. Perhaps it is some strange compatibility with sqlite3.

I need to know if this is a bug, a workaround, or working as intended so I can modify my code appropriately?

Attachments

Change History

07/25/06 23:51:06 changed by mir@noris.de

  • cc set to mir@noris.de.

07/26/06 11:25:35 changed by scanner@nominum.com

Oh, another note - this can be related to ticket #2417 - when I define a binary type field (in my own project subclassing models.CharField?, and defining the appropriate db type in the db creation.py module, 'ilike' is not a valid operator for on such a field for obvious reasons whereas 'like' is.

10/23/06 02:26:04 changed by mir@noris.de

  • cc deleted.

removed myself from Cc since ticket starts to get spammed :-(

01/16/07 17:36:41 changed by Robert Myers <myer0052@gmail.com>

SQLite doesn't support case-sensitive LIKE statements. From the Django documentation itself. This ticket should be closed.

01/16/07 18:21:19 changed by Robert Myers <myer0052@gmail.com>

Should have provided a handy link, here goes: http://www.djangoproject.com/documentation/db_api/#iexact maybe the text below contains should be copied to exact as well.

  • SQLite doesn't support case-sensitive LIKE statements; exact acts like iexact for SQLite.

01/17/07 17:42:51 changed by Gary Wilson <gary.wilson@gmail.com>

  • status changed from new to closed.
  • resolution set to invalid.

What Robert said.

03/02/07 03:11:52 changed by Bastian Kleineidam <calvin@debian.org>

  • status changed from closed to reopened.
  • resolution deleted.

I encountered the same bug today as the original submitter: I specified uniqueness, but django complained about duplicate field values.

I don't use sqlite, but postgresql, and I fixed the bug by replacing all 'iexact' with 'exact' in db/models/manipulators.py:manipulator_validator_unique_together().

03/07/07 23:37:33 changed by Simon G. <dev@simon.net.nz>

  • keywords set to SQlite.
  • status changed from reopened to closed.
  • resolution set to invalid.
  • summary changed from unique_together uses 'iexact' matching, I expected this to be 'exact' to unique_together on SQLite uses 'iexact' matching, I expected this to be 'exact'.

Hi Bastian, I don't think these issues are related other than the case sensitivity. The original bug here was to do with SQLite's lack of a case sensitive match, whilst your problem is in the manipulators (which directly specifies iexact). This is a design issue I think, IMO case insensitive matches are the most common idea (i.e. we don't want a "Simon" and a "SImon" in the database), but this might be nice to have as an option.

Long story short - Can you create a new ticket for this issue?

Thanks :) Simon


Add/Change #2422 (unique_together on SQLite uses 'iexact' matching, I expected this to be 'exact')




Change Properties
Action