Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush cache after the current transaction is committed (#296) #300

Merged
merged 1 commit into from Jul 17, 2018

Conversation

dtao
Copy link
Contributor

@dtao dtao commented Jul 14, 2018

This builds off the work in pull request #299 and fixes the issue raised in #296.

Note: review #299 before reviewing this.

@dtao dtao force-pushed the invalidate-cache-on-commit branch from bc36a48 to b2ea258 Compare July 14, 2018 21:51
@@ -3,14 +3,14 @@
from decimal import Decimal

from django.contrib.auth.models import AnonymousUser
from django.test import TestCase, RequestFactory
from django.test import TransactionTestCase, RequestFactory
Copy link
Contributor Author

@dtao dtao Jul 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django's TestCase class automatically wraps each test method in a transaction and rolls back the transaction after the method returns. Since updating models now doesn't flush the cache until after the transaction is committed, this breaks the logic in most of these tests. Inheriting from TransactionTestCase addresses the problem by removing Django's magical auto-rollback behavior, the trade-off being that the tests are a tad slower.

@dtao
Copy link
Contributor Author

dtao commented Jul 14, 2018

I suppose you could technically merge this before merging #299; there would just effectively be no test coverage since the test added in this PR is skipped when running tests with sqlite.

Copy link
Collaborator

@jsocol jsocol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, thanks @dtao! I think we should wait and merge #299 first then get this one in—I'd rather watch the new CI build on master succeed without this patch first.

'This test uses threads, which the sqlite3 DB engine '
'does not support.')
def test_update_switch_in_transaction(self):
"""Wait to invalidate the cache until after the current transaction."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate all the comments here, this is definitely not an obvious issue.

Would you mind adding a slightly longer description to the doc block (as a second paragraph) and include a link to #296?

Should we have similar tests for Flag and Sample? I know the behavior exists in BaseModel but that's an implementation detail, not a public API. If we needed to refactor it, especially in support of extensible models, it could change or break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, I can add another comment explicitly referencing #296.

I'm also happy to add equivalent tests for Flag and Sample.

@dtao dtao force-pushed the invalidate-cache-on-commit branch from b2ea258 to 52d3b4a Compare July 15, 2018 21:07
@dtao
Copy link
Contributor Author

dtao commented Jul 15, 2018

@jsocol Per your suggestions I've added an explanatory comment to the somewhat complex test method to cover this case and also updated the test code to cover flags, switches, and samples.

I squashed this work into one commit because I think that's what you prefer, though I acknowledge that can make it hard to tell what changed since you last reviewed the code. If I've misunderstood, and for future reference I should not squash commits in pull requests that are under review, let me know.

@dtao
Copy link
Contributor Author

dtao commented Jul 17, 2018

Hey @jsocol @clintonb just making sure: with #299 merged, is this PR waiting on me for anything right now? I'm happy to wait patiently; I just don't want to be neglectful if there's something I should be doing to get this PR merged that I've overlooked.

@clintonb clintonb merged commit 7f5d540 into jazzband:master Jul 17, 2018
@dtao
Copy link
Contributor Author

dtao commented Aug 5, 2018

Is there any interest in releasing a new version with this fix?

We are just depending on a fork at the moment. It's always nice to return to the fold when we can :)

@clintonb
Copy link
Collaborator

clintonb commented Aug 6, 2018

I can take the steps to start a release, but I can't actually merge the requisite changes without @jsocol. I've been trying to get merge rights, but I haven't received a response on #278.

I'd recommend either sticking with your fork, or using the latest commit on master for the time being, @dtao.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants