Opened 17 years ago

Closed 15 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: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Download all attachments as: .zip

Change History (8)

by Antti Kaihola, 17 years ago

Attachment: manual_pk_quote.diff added

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

comment:1 by Chris Beaven, 17 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

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

by Antti Kaihola, 17 years ago

Attachment: pg_capital_pk_test.diff added

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

comment:2 by Antti Kaihola, 17 years ago

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

by Antti Kaihola, 17 years ago

Attachment: manual_pk_quote_6137.dff added

updated patch for revision 6137

by Antti Kaihola, 17 years ago

Attachment: manual_pk_quote_6137.2.dff added

now uses the new qn() function for quoting

comment:3 by Antti Kaihola, 17 years ago

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

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