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

Async race condition fix - Moved publishing to transaction post-commit #711

Closed

Conversation

Abdul-Dridi
Copy link
Contributor

Our wagtail setup has us processing wagtail signals asynchronously (in celery tasks), we've noticed that when publishing localised content, the tasks asynchronous page database query oftentimes retrieves the page state before the translations have been synced.

From our testing, this occurs when a page db query is made before the translation transaction has been committed.

This pr pushes the page revision publish to be executed after the transaction has been successfully committed.

@zerolab
Copy link
Collaborator

zerolab commented Sep 6, 2023

@Abdul-Dridi thank you for this. Could you add a test or a few for the change?

@Abdul-Dridi
Copy link
Contributor Author

@zerolab I've updated the existing tests, which were failing because the transaction wasn't committed.
Did you also want me to write tests to explicity test pre commit vs post commit state?

is_lazy=True,
),
test_snippet=self.snippet,
with patch.object(transaction, "on_commit", side_effect=lambda func: func()):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really don't think these setup tasks need to be wrapped like this.
we are only interested on the create/update translation tests to issue a on_commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point, moved the patch to an overriden setup method in the relevant test class. (I'm wrapping the setup task because the Translation.save_target method used executes my changed code)

Unless I'm missing something, the only way to bring the patch into the test_edit_page_translation method itself would be to split up the setup method and call the relevant part of it in the actual test

@codecov-commenter
Copy link

codecov-commenter commented Sep 25, 2023

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.32%. Comparing base (e2de395) to head (3ce1f7e).
Report is 100 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #711      +/-   ##
==========================================
+ Coverage   93.27%   93.32%   +0.05%     
==========================================
  Files          47       47              
  Lines        3908     3908              
  Branches      579      579              
==========================================
+ Hits         3645     3647       +2     
+ Misses        154      153       -1     
+ Partials      109      108       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerolab
Copy link
Collaborator

zerolab commented Oct 1, 2023

Thank you for this @Abdul-Dridi, tidied up, brought up to date with main and merged in #720

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.

3 participants