﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4972	manage.py inspectdb fails with TypeError	ssbg@…	nobody	"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 ([[BR]]
flock_book_vol VARCHAR(2) NOT NULL,[[BR]]
member_no VARCHAR(6) NOT NULL REFERENCES member (member_no),[[BR]]
copies INT NOT NULL,[[BR]]
date_ordered DATE NOT NULL,[[BR]]
CONSTRAINT fbk_order_key PRIMARY KEY (flock_book_vol, member_no))[[BR]]
WITHOUT OIDS;[[BR]]

fails with a !TypeError at line 38 of introspection.py in get_relation():[[BR]]

37    # row![0] and row![1] are like ""{2}"", so strip the curly braces.[[BR]]
38    relations[int(row![0][1:-1]) - 1] = (int(row![1][1:-1]) - 1, row![2])[[BR]]
!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:[[BR]]

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.


"		closed	django-admin.py inspectdb	0.96		worksforme	inspectdb TypeError get_relation foreign key postgresql		Unreviewed	0	0	0	0	0	0
