Opened 11 years ago

Closed 11 years ago

#4972 closed (worksforme) inspectdb fails with TypeError

Reported by: ssbg@… Owned by: nobody
Component: inspectdb Version: 0.96
Severity: Keywords: inspectdb TypeError get_relation foreign key postgresql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Windows XP Pro,
PostgreSQL 8.1,
Django 0.96,
Python 2.4.1,
psycopg 2.0.6

Running managepy inspectdb against a postgresql database containing a table witht foreign key created with:

CREATE TABLE fbk_order (
flock_book_vol VARCHAR(2) NOT NULL,
member_no VARCHAR(6) NOT NULL REFERENCES member (member_no),
copies INT NOT NULL,
date_ordered DATE NOT NULL,
CONSTRAINT fbk_order_key PRIMARY KEY (flock_book_vol, member_no))

fails with a TypeError at line 38 of in get_relation():

37 # row[0] and row[1] are like "{2}", so strip the curly braces.
38 relations[int(row[0][1:-1]) - 1] = (int(row[1][1:-1]) - 1, row[2])
TypeError: int() argument must be a string or a number

The row returned by postgresql is not in the format indicated by the comment. row[0] and row[1] are
actually arrays of smallints, not strings - potentially more than one field could be involved in the relationship. For a single relationship line 38 should be replaced with:

relations[int(row[0][0]) - 1] = (int(row[1][0]) - 1, row[2])

If Django can handle multiple foreign key fields from one table then code should be added to handle an array size > 1.

Change History (1)

comment:1 Changed 11 years ago by Michael Radziej

Component: inspectdb
Keywords: postgresql added
Resolution: worksforme
Status: newclosed

I'm quite confident that this has been fixed in the current trunk. Please re-open if you have tested with a current version and the bug is still there.

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