Opened 8 years ago

Closed 8 years ago

#26299 closed Uncategorized (invalid)

Rollback bug on Postgres for multidb applications

Reported by: Silvio J. Gutierrez Owned by: nobody
Component: Uncategorized Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi there,

Was putting together a fairly straightforward multidb project:

  1. Most models go in db1
  2. Some models in a special app go to db2.
  3. Models from db2 don't ever communicate with db1.

Noticed that, in tests, rollbacks do not work for models in db2. I thought it could be environmental, but I setup a very simple project to reproduce, see https://github.com/silviogutierrez/django-multidb-bug

You just need to install the requirements, activate the virtual env and run python manage.py test --keepdb *twice*. You'll notice the model created in the test are not cleared.

Note that it is the --keepdb flag that triggers the bug, as uniqueness constraints will fail for unique fields.

For the purposes of this demo, and just to reproduce this bug, I routed all requests to db2.

Hope this helps someone. Oddly enough, I do see a rollback statement in my DB logs, but it doesn't "take."

Thanks for an awesome project,

Silvio

Change History (4)

comment:1 by Tim Graham, 8 years ago

Does adding multi_db = True to your TestCase help?

comment:2 by Silvio J. Gutierrez, 8 years ago

It does! That seems to fix it.

So is this a documentation gap then? Or should the rollback behavior automatically apply based on the router?

Ideally the latter, I think, but even the former would help others avoid this.

comment:3 by Tim Graham, 8 years ago

Where do you think the documentation gap is? Is something missing in the section I linked?

comment:4 by Tim Graham, 8 years ago

Resolution: invalid
Status: newclosed

Please open a new ticket if you believe any documentation is missing. Thanks!

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