Opened 9 years ago

Closed 8 years ago

#4736 closed (fixed)

manually named primary key columns not properly quoted

Reported by: Antti Kaihola 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 Antti Kaihola 9 years ago.
adds manual pk column name quoting to the save() method
pg_capital_pk_test.diff (527 bytes) - added by Antti Kaihola 9 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 Antti Kaihola 9 years ago.
updated patch for revision 6137
manual_pk_quote_6137.2.dff (936 bytes) - added by Antti Kaihola 9 years ago.
now uses the new qn() function for quoting

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by Antti Kaihola

Attachment: manual_pk_quote.diff added

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

comment:1 Changed 9 years ago by Chris Beaven

Needs tests: set
Triage Stage: UnreviewedAccepted

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

Changed 9 years ago by Antti Kaihola

Attachment: pg_capital_pk_test.diff added

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

comment:2 Changed 9 years ago by Antti Kaihola

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

Changed 9 years ago by Antti Kaihola

Attachment: manual_pk_quote_6137.dff added

updated patch for revision 6137

Changed 9 years ago by Antti Kaihola

Attachment: manual_pk_quote_6137.2.dff added

now uses the new qn() function for quoting

comment:3 Changed 9 years ago by Antti Kaihola

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 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

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