Code

Opened 8 years ago

Closed 8 years ago

#2164 closed defect (fixed)

[patch] Update SQL incorrect when db_column different to field name

Reported by: Russell Cloran <russell@…> Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi,

When database column name is different to the field's name (attname), the update SQL is generated incorrectly. The following trivial patch fixes that:

--- django/db/models/base.py    (revision 3129)
+++ django/db/models/base.py    (working copy)
@@ -165,7 +165,7 @@
                 cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
                     (backend.quote_name(self._meta.db_table),
                     ','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
-                    backend.quote_name(self._meta.pk.attname)),
+                    backend.quote_name(self._meta.pk.column)),
                     db_values + [pk_val])
             else:
                 record_exists = False

Russell

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by mtredinnick

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

(In [3130]) Fixed #2164 -- Create correct SQL when pk column name is not the same as the
attribute name. Thanks, Russell Cloran.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.