Django

Code

Ticket #2164 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: Russell Cloran <russell@hbd.com> Assigned to: adrian
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Change History

06/15/06 06:28:33 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #2164 ([patch] Update SQL incorrect when db_column different to field name)




Change Properties
Action