Django

Code

Ticket #5710 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: davep@atomicdroplet.com Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: manage.py loaddata dumpdata postgresql
Cc: gary.wilson@gmail.com, real.human@mrmachine.net, arthur.case@gmail.com, tom@eggdrop.ch, mark@tranchant.co.uk, portland@chrominance.net, floguy@gmail.com, django@versea.be, remco@diji.biz, eliott@cactuswax.net, pythonmailing@web.de Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

operations_py.patch (0.5 kB) - added by davep@atomicdroplet.com on 10/08/07 22:07:00.
Patch against revision 6468 to fix postgresql m2m loaddata problem

Change History

10/08/07 22:07:00 changed by davep@atomicdroplet.com

  • attachment operations_py.patch added.

Patch against revision 6468 to fix postgresql m2m loaddata problem

10/08/07 22:10:28 changed by davep@atomicdroplet.com

  • cc set to gary.wilson@gmail.com, real.human@mrmachine.net, arthur.case@gmail.com, tom@eggdrop.ch, mark@tranchant.co.uk, portland@chrominance.net, floguy@gmail.com, django@versea.be, remco@diji.biz, eliott@cactuswax.net, pythonmailing@web.de.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

10/08/07 22:12:07 changed by SmileyChris

  • 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.

10/14/07 00:53:56 changed by gwilson

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #5710 (dumpdata/loaddata fails with many-to-many tables on postgresql)




Change Properties
Action