Opened 18 years ago
Closed 18 years ago
#4972 closed (worksforme)
manage.py inspectdb fails with TypeError
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | django-admin.py 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 | 
Description
System:
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))
WITHOUT OIDS;
fails with a TypeError at line 38 of introspection.py 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 by , 18 years ago
| Component: | Tools → django-admin.py inspectdb | 
|---|---|
| Keywords: | postgresql added | 
| Resolution: | → worksforme | 
| Status: | new → closed | 
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.