Opened 18 years ago

Closed 17 years ago

#3201 closed defect (duplicate)

PostgreSQL index introspection fails on tables (get relations)

Reported by: j.states@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: major Keywords: postgresql
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

class StaffSessions(models.Model):
Traceback (most recent call last):

File "theirry/manage.py", line 11, in <module>

execute_manager(settings)

File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management.py", line 1447, in execute_manager

execute_from_command_line(action_mapping, argv)

File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management.py", line 1358, in execute_from_command_line

for line in action_mapping[action]():

File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/management.py", line 762, in inspectdb

relations = introspection_module.get_relations(cursor, table_name)

File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/db/backends/postgresql_psycopg2/introspection.py", line 35, in get_relations

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

Attachments (3)

django-postgres-introspection.diff (489 bytes ) - added by j.states@… 18 years ago.
Patch for this ticket, please review
ticket_3201_sample.sql (3.5 KB ) - added by j.states@… 18 years ago.
Test Schema and Table for replication of problem
ticket_3201_sample.2.sql (3.5 KB ) - added by j.states@… 18 years ago.
Use this to create a schema and table, After creating the schema, change your settings to that schema and table, then try inspectdb. The errors should be replicated.

Download all attachments as: .zip

Change History (13)

comment:1 by jstates@…, 18 years ago

Sorry, I forgot to tell you that I'm using reference constraints with PostgreSQL and removing the reference constraint removes the errors.

by j.states@…, 18 years ago

Patch for this ticket, please review

comment:2 by mir@…, 18 years ago

Has patch: set
Needs tests: set
Patch needs improvement: set

Hmm, I don't get what your patch is fixing. There's only a traceback in the ticket. What is the problem behind it? How was the traceback created? What exception is thrown?

Can you give us the sql statements that create the database where introspection failed? This would sufficient to answer all my questions above.

Regarding your patch, the comment right above contradicts your patch. Shouldn't it also be mended?

comment:3 by mir@…, 18 years ago

Trying again to reach you:

Hmm, I don't get what your patch is fixing. There's only a traceback in the ticket. What is the problem behind it? How was the traceback created? What exception is thrown?

Can you give us the sql statements that create the database where introspection failed? This would sufficient to answer all my questions above.
Regarding your patch, the comment right above contradicts your patch. Shouldn't it also be mended?

by j.states@…, 18 years ago

Attachment: ticket_3201_sample.sql added

Test Schema and Table for replication of problem

by j.states@…, 18 years ago

Attachment: ticket_3201_sample.2.sql added

Use this to create a schema and table, After creating the schema, change your settings to that schema and table, then try inspectdb. The errors should be replicated.

comment:4 by mir@…, 18 years ago

Thanks, that will help!

comment:5 by md@…, 18 years ago

Isn't this a dublicate of Ticket #2591?

comment:6 by j.states@…, 18 years ago

It appears to be similar, I will test that change. The different is that I used schemas with constraints and cascading deletes and ticket #2591 does not.

comment:7 by j.states@…, 18 years ago

I know that this is a trivia problem, but I svn .97-pre and had to re-patch postgresql base.py and introspection as it caused my model to display errors. Please review my recommendations and commit, please.

comment:8 by Michael Radziej <mir@…>, 18 years ago

Triage Stage: UnreviewedAccepted

I have verified that the bug exists with postgresql_psycopg2, but the patch is not correct.

When I try your schema with psycopg and psycopg2, I get these differences in the created models:

--- /tmp/mod1.py	2007-04-24 13:04:45.000000000 +0200
+++ /tmp/mod2.py	2007-04-24 13:04:06.000000000 +0200
@@ -12,18 +12,18 @@
 class Admin(models.Model):
     admin_id = models.IntegerField(primary_key=True)
     firstname = models.CharField(maxlength=100)
     lastname = models.CharField(maxlength=150)
-    username = models.ForeignKey(Staff, db_column='username')
+    username = models.CharField(maxlength=50)
     email = models.CharField(unique=True, maxlength=150)
     department = models.CharField(maxlength=150)
-    last_login = models.ForeignKey(Staff, db_column='last_login')
+    last_login = models.DateTimeField()
     admin_level = models.SmallIntegerField()
-    staff = models.ForeignKey(Staff)
+    staff_id = models.SmallIntegerField()
     mail_comments = models.BooleanField()
     mail_trackback = models.BooleanField()
     publish_right = models.BooleanField()
-    last_updated = models.ForeignKey(Staff, db_column='last_updated')
+    last_updated = models.DateTimeField()
     class Meta:
         db_table = 'admin'
 
 class Users(models.Model):
@@ -43,9 +43,9 @@
     category_id = models.IntegerField(primary_key=True)
     name = models.CharField(maxlength=255)
     icon = models.CharField(maxlength=255)
     description = models.TextField()
-    author = models.ForeignKey(Staff)
+    author_id = models.SmallIntegerField()
     category_left = models.SmallIntegerField()
     catefory_right = models.SmallIntegerField()
     parent_id = models.SmallIntegerField()
     class Meta:

The patch fails to detect foreign key constraints. I use postgresql 8.1.8 (ubuntu-dapper) and psycopg 2.0 (self-compiled)

comment:9 by j.states@…, 18 years ago

The patch provided with Ticket #2591 now solves this problem. It did not when I posted this ticket. I would add the change to SVN if possible.

comment:10 by Gary Wilson, 17 years ago

Resolution: duplicate
Status: newclosed

dup of #2591.

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