Code

Opened 7 years ago

Closed 7 years ago

Last modified 2 years ago

#5710 closed (fixed)

dumpdata/loaddata fails with many-to-many tables on postgresql

Reported by: davep@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: manage.py loaddata dumpdata postgresql
Cc: gary.wilson@…, real.human@…, arthur.case@…, tom@…, mark@…, portland@…, floguy@…, django@…, remco@…, eliott@…, pythonmailing@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I did a (manage.py) dumpdata then loaddata with some models that had many to many fields. The subsequent loaddata operation failed with an error:

psycopg2.ProgrammingError: relation "keywordsites_site__site__keywords" does not exist.

The problem is that the name of the table is reduced to lower case where the name of the table is actually has an uppercase S

keywordsites_site__Site__keywords

and further investigation revealed that the generated SQL had the correct capitalisation but the table name was not quoted - hence the problem.

The fix is to change line 96 on django/db/backends/postgresql/operations.py to:

                output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s \"%s\";" % \

No idea how to make a .diff, sorry, but for a single line I'm sure you can cope. It would be nice to be able to turn WikiFormatting off inline too.

Attachments (1)

operations_py.patch (552 bytes) - added by davep@… 7 years ago.
Patch against revision 6468 to fix postgresql m2m loaddata problem

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by davep@…

Patch against revision 6468 to fix postgresql m2m loaddata problem

comment:1 Changed 7 years ago by davep@…

  • Cc gary.wilson@…, real.human@…, arthur.case@…, tom@…, mark@…, portland@…, floguy@…, django@…, remco@…, eliott@…, pythonmailing@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

After critical review (thanks SmileyChris) it appears there is a qn() call to use the backend's quoting mechanism. A patch using this significantly more correct method is attached.

comment:2 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Ready for checkin

This is a simple and obviously correct change so I won't ask for tests, however the committer might. You can see from the very similar code 10 lines above this change that it should be quoted.

comment:3 Changed 7 years ago by gwilson

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

(In [6507]) Fixed #5710 -- Fixed a missing table name quoting in the postgresql backend, thanks davep@….

comment:5 Changed 2 years ago by aaugustin

Revert spam (that I'm going to delete).

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.