Opened 6 years ago

Closed 6 years ago

#13492 closed (invalid)

get_or_create(field__iexact=value) fails to set value.

Reported by: Chris Dukes <pakraticus@…> Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by russellm)

I'm not sure if this is a documentation bug, or a code bug, or operator headspace error.

I have a model where a column needs to be unique in a case insensitive fashion, but should be stored in a case sensitive fashion.
I have applied custom SQL for that constraint.

As I am bulk loading the table, I am making use of get_or_create(field0__iexact=value0, field1=value1).
When I use this invocation, field0 ends up being set as null.

If I invoke it as get_or_create(field0__iexact=value0, field0=value0, ...)
I eventually have a constraint error.

I would expect a FieldError if field0__iexact were not permitted, and I would expect the fieldname to be calculated from field0__iexact if it were permitted.

I am currently avoiding the problem by catching an exception on psycopg2.IntegrityError, but that does not seem to be the right solution.

Chris Dukes

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Sounds like you've missed the section on defaults in the docs.

For future reference, if you're uncertain if you've found a bug, it's better to ask on django-users first.

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