Closed tobiasmcnulty closed 9 years ago
@Bpless @tgross @jbalogh I believe the Multi DB changes in PR #29 / PR #36 caused a regression described by the test in this PR (https://github.com/django-cache-machine/django-cache-machine/pull/105/files#diff-7053fe2d125e8267cc59b02ee849855bR569).
I can think of a few ways to fix this but am not sure what would be best:
allow_relation
in the appropriate DB router to allow relations between objects in the master & slave DBs (if the use case here is really a master/slave setup, it shouldn't matter what DB the object(s) came from): https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#allow_relation_state.db
with a DB key to match the one of the original request, using a method similar to this: https://gist.github.com/tobiasmcnulty/2906c06b7498b3978867 (not sure this would work either)Would appreciate any feedback!
Thanks.
@Bpless @tgross @jbalogh I took a stab at option 1; would appreciate any feedback.
Also @kmtracey ^^
In 0.8, a regression was introduced (I believe by the changes in PR #29 or PR #36) that broke invalidation when an object previously cached from a slave database was later modified via the master database.
This test and change fixes that by removing the database from the flush key, thereby creating flush lists that are shared across databases. Objects are still cached per DB (so
obj._state.db
will be correct), but all cached objects/queries across DBs should be invalidated when one changes.Getting this test working required a few changes to the way multi-DB tests are run, namely:
TEST_MIRROR
setting rather than simply duplicating the test data across DBs (without this, there's no way to remove an object from one DB without invalidating it on that DB)TransactionTestCase
(undocumented, but required by TEST_MIRROR setting)TEST_MIRROR
also does not appear to work with sqlite)