Code

Opened 7 years ago

Closed 7 years ago

#3201 closed defect (duplicate)

PostgreSQL index introspection fails on tables (get relations)

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

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@… 7 years ago.
Patch for this ticket, please review
ticket_3201_sample.sql (3.5 KB) - added by j.states@… 7 years ago.
Test Schema and Table for replication of problem
ticket_3201_sample.2.sql (3.5 KB) - added by j.states@… 7 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 Changed 7 years ago by jstates@…

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

Changed 7 years ago by j.states@…

Patch for this ticket, please review

comment:2 Changed 7 years ago by mir@…

  • 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 Changed 7 years ago by mir@…

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?

Changed 7 years ago by j.states@…

Test Schema and Table for replication of problem

Changed 7 years ago by j.states@…

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 Changed 7 years ago by mir@…

Thanks, that will help!

comment:5 Changed 7 years ago by md@…

Isn't this a dublicate of Ticket #2591?

comment:6 Changed 7 years ago by j.states@…

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 Changed 7 years ago by j.states@…

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 Changed 7 years ago by Michael Radziej <mir@…>

  • Triage Stage changed from Unreviewed to Accepted

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 Changed 7 years ago by j.states@…

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 Changed 7 years ago by gwilson

  • Resolution set to duplicate
  • Status changed from new to closed

dup of #2591.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.