Opened 17 years ago

Closed 17 years ago

#5366 closed (fixed)

sequence_reset_sql table name quoting problem (PostgreSQL backend)

Reported by: alex@… Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: quote fixture postgresql
Cc: alex@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have recently run into trouble of using fixtures with PostgreSQL. Any attempt to use them for my application
produced a number of SQL errors of not existing tables. I found that this problem was caused by missing
quoting of a table name, added it, and it fixed the problem.

Index: django/db/backends/postgresql/operations.py
===================================================================
--- django/db/backends/postgresql/operations.py (revision 6066)
+++ django/db/backends/postgresql/operations.py (working copy)
@@ -100,5 +100,5 @@
                     style.SQL_FIELD(qn('id')),
                     style.SQL_KEYWORD('IS NOT'),
                     style.SQL_KEYWORD('FROM'),
-                    style.SQL_TABLE(f.m2m_db_table())))
+                    style.SQL_TABLE(qn(f.m2m_db_table()))))
         return output


To reproduce problem:

  1. Use postgresql_psycopg2 as your database adapter
  2. Name one of your application with big case letter (ex: instead of fixtures_regress application I had to name it FixturesRegress)
  3. Try to dumpdata/loaddata.

Got:

SELECT ... FROM FixturesRegress_stuff_shared_with;

Must be:

SELECT ... FROM "FixturesRegress_stuff_shared_with"

PosgreSQL reaction to a wrong quoting:

    ProgrammingError: relation "fixturesregress_stuff_shared_with" does not exist

The difference is that quoting must be present in table name for !PostgreSQL to recognize this table.

Since successful testing depends on application name, we can not use our fixtures_regress folder to just add a
single test.

To prove the problem existence I have made a simple test app and attaching it to this ticket,
as a ready test, but please fix me and provide a different patch if this is not the kind of test you require
for a successful ticket acceptance.

Attachments (1)

alex_db_operations.diff (553 bytes ) - added by alex@… 17 years ago.
Patch to fix table quoting

Download all attachments as: .zip

Change History (3)

by alex@…, 17 years ago

Attachment: alex_db_operations.diff added

Patch to fix table quoting

comment:1 by alex@…, 17 years ago

I can not add test file to this ticket due to "Trac internal server error" (see http://pastebin.com/m4149437f) so
I have posted zip archive with test on my site: http://www.halogen-dg.com/alex/MyTests.zip

comment:2 by Gary Wilson, 17 years ago

Resolution: fixed
Status: newclosed

This was fixed in [6507]. The MyTests.zip file doesn't seem to exist anymore. Tests would be nice though, so if you still have them please open a new ticket.

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