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
--
Ticket URL: <https://code.djangoproject.com/ticket/26299>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Does adding
[https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.TransactionTestCase.multi_db
multi_db = True] to your `TestCase` help?
--
Ticket URL: <https://code.djangoproject.com/ticket/26299#comment:1>
Comment (by silviogutierrez):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26299#comment:2>
Comment (by timgraham):
Where do you think the documentation gap is? Is something missing in the
section I linked?
--
Ticket URL: <https://code.djangoproject.com/ticket/26299#comment:3>
* status: new => closed
* resolution: => invalid
Comment:
Please open a new ticket if you believe any documentation is missing.
Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/26299#comment:4>