Opened 8 years ago

Closed 7 years ago

#4736 closed (fixed)

manually named primary key columns not properly quoted

Reported by: akaihola Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If the database column for a primary key is named manually using db_column= and the name contains capital letters, objects can't be saved (at least on PostgreSQL) since the column name is not properly quoted in django.db.models.save().

PostgreSQL or psycopg2 seems to convert unquoted column names to all lower case, and this has to be protected with quotes.

Attachments (4)

manual_pk_quote.diff (874 bytes) - added by akaihola 8 years ago.
adds manual pk column name quoting to the save() method
pg_capital_pk_test.diff (527 bytes) - added by akaihola 8 years ago.
revised test case for primary key db_column with upper case in the name
manual_pk_quote_6137.dff (952 bytes) - added by akaihola 8 years ago.
updated patch for revision 6137
manual_pk_quote_6137.2.dff (936 bytes) - added by akaihola 8 years ago.
now uses the new qn() function for quoting

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by akaihola

adds manual pk column name quoting to the save() method

comment:1 Changed 8 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Sounds like a valid bug to me, want to add a test case?

Changed 8 years ago by akaihola

revised test case for primary key db_column with upper case in the name

comment:2 Changed 8 years ago by akaihola

Hmm, the test I just submitted now passes. Maybe this has already been fixed?

Changed 8 years ago by akaihola

updated patch for revision 6137

Changed 8 years ago by akaihola

now uses the new qn() function for quoting

comment:3 Changed 8 years ago by akaihola

  • Needs tests unset

Ok I'm not sure why the test passes also without my patch. Might be PostgreSQL versions. I'm testing with 8.2 now, and I might have been using 8.0 or 8.1 when I submitted this ticket.

Anyway, looking at the code it seems to me that the qn() is really meant to be used there.

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

All field objects are handed through to the backend and treated consistently now (post queryset-refactor merge), so this doesn't appear to be an issue any longer.

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