sequence_reset_sql table name quoting problem (PostgreSQL backend)
|Reported by:||alex@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Severity:||Keywords:||quote fixture postgresql|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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:
- Use postgresql_psycopg2 as your database adapter
- Name one of your application with big case letter (ex: instead of fixtures_regress application I had to name it FixturesRegress)
- Try to dumpdata/loaddata.
SELECT ... FROM FixturesRegress_stuff_shared_with;
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
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.