Skip to content

ref(hc): Adding helpers for managing transactions #52943

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

Merged
merged 4 commits into from
Jul 18, 2023

Conversation

corps
Copy link
Contributor

@corps corps commented Jul 15, 2023

  1. Adds helper such that during a transaction, no executes occur on a differing connection
  2. Adds helper to collect transaction spans queries run on them, making it possible to write a test assertion about the transactional spans of methods.

@corps corps requested review from markstory and a team July 15, 2023 05:25
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 15, 2023
@codecov
Copy link

codecov bot commented Jul 15, 2023

Codecov Report

Merging #52943 (d840033) into master (411cea3) will increase coverage by 0.00%.
The diff coverage is 96.49%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #52943   +/-   ##
=======================================
  Coverage   79.46%   79.46%           
=======================================
  Files        4936     4936           
  Lines      207433   207481   +48     
  Branches    35426    35433    +7     
=======================================
+ Hits       164832   164881   +49     
  Misses      37562    37562           
+ Partials     5039     5038    -1     
Impacted Files Coverage Δ
src/sentry/testutils/silo.py 84.11% <33.33%> (-0.80%) ⬇️
src/sentry/db/postgres/transactions.py 86.36% <100.00%> (ø)
src/sentry/testutils/hybrid_cloud.py 88.52% <100.00%> (+5.68%) ⬆️

... and 10 files with indirect coverage changes

with transaction.atomic(using=router.db_for_write(Organization)):
Factories.create_organization()

with django_test_transaction_water_mark():
Copy link
Member

Choose a reason for hiding this comment

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

Is the idea that we'll use django_test_transaction_water_mark() to escape the concurrent transaction detection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markstory

django_test_transaction_water_mark is used to mark a place when normally, a separate process would be occurring, and thus there would be no other baseline transactions. In a way, it escapes things like transaction.on_commit and the enforce_no_transaction and now the mixed transaction detection so that they don't get mixed up with these outer transactions that would not exist in production.

Examples include:

  1. celery jobs being run synchronously (outboxes)
  2. initial transactions wrapping tests
  3. rpc that would be hitting a separate endpoint.

self.alias in open_transactions
), f"Transaction opened for db {open_transactions}, but command running against db {self.alias}"

return execute(*params)
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything we could wrap this in that would need **kwargs as well?

@corps corps merged commit 2be79be into master Jul 18, 2023
@corps corps deleted the zc/transaction-utilities branch July 18, 2023 15:59
GabeVillalobos added a commit that referenced this pull request Jul 19, 2023
…using unguarded_write decorators (#53160)

With the inclusion of our recent changes to transaction validations in
PR #52943 and the inclusion of 'using' in all of our
transactions/helpers thanks to PRs #53027 and #53004, we should be able
to safely remove the ability to specify a transaction without a using
keyword arg.

Because this is now mandatory, it should also be safe to remove
autorouting, which ended up being incorrect in many testing contexts
anyway.

This is a resubmission of PR #53080 which was reverted due to broken
load-mocks and a single broken getsentry migration test.
@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants