Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14796 closed (fixed)

inspectdb producing field names which are Python keywords

Reported by: pappjm@… Owned by: mmcnickle
Component: django-admin.py inspectdb Version: 1.2
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

Similar to #1328; I had a case where inspectdb produced a model which uses a python keyword as a field in the model class.

  • Django: 1.2.3
  • Python: 2.6.5
  • DB Driver: postgresql_psycopg2

I will attach an SQL file; it is from the Danbooru image server. The table which had the problems is "dmails"; the column is a foreign key column to the table "users".

Attachments (4)

danbooru.sql (74.0 KB ) - added by pappjm@… 14 years ago.
Schema of the database which inspectdb is failing on
minimal.sql (911 bytes ) - added by mmcnickle 14 years ago.
Minimal MySQL schema to reproduce problem
move_keyword_check.diff (1.4 KB ) - added by mmcnickle 14 years ago.
Move the keyword check after the relations check/modifications
14796-move_keyword_check_with_tests.diff (3.9 KB ) - added by mmcnickle 14 years ago.
Improved the test by using the pre-existing stdout capture method, updated inspectdb.py to take advantage of it.

Download all attachments as: .zip

Change History (9)

by pappjm@…, 14 years ago

Attachment: danbooru.sql added

Schema of the database which inspectdb is failing on

comment:1 by Ramiro Morales, 14 years ago

Triage Stage: UnreviewedAccepted

As suspected, this happens because one transformation made to field names after the verification against the Python keyword list (namely the striping of '_id' from e.g. 'from_id') can result in a 'from' introspected model field name. There are a couple of that kind of transformations.

comment:2 by mmcnickle, 14 years ago

Owner: changed from nobody to mmcnickle
Status: newassigned

by mmcnickle, 14 years ago

Attachment: minimal.sql added

Minimal MySQL schema to reproduce problem

by mmcnickle, 14 years ago

Attachment: move_keyword_check.diff added

Move the keyword check after the relations check/modifications

comment:3 by mmcnickle, 14 years ago

Has patch: set

by mmcnickle, 14 years ago

Improved the test by using the pre-existing stdout capture method, updated inspectdb.py to take advantage of it.

comment:4 by Ramiro Morales, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r15296.

comment:5 by Ramiro Morales, 14 years ago

(In [15301]) [1.2.X] Fixed #14796 -- Modified order of operations performed on field names by the inspectdb command so it doesn't generates model fields with names equal to Python keywords. Thanks pappjm at gmail dot com for the report, mmcnickle for the fix and Alex for simplifying the tests.

Backport of r15296 and r15297 from trunk.

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