-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Allow providers to override ambient transaction access #24209
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to just wrap Transaction.Current
and expose it on ITransactionEnlistmentManager
, this way all places using it would benefit.
Good point for doing it for other places (e.g. BatchExecutor). Though the intent here was to also allow skipping the _ambientTransactions checks that come after (Count, TryPeek), i.e. to skip HandleAmbientTransactions altogether (even if perf-wise it's probably not very significant). Should we do both? Am OK to also only do Transaction.Current. |
&& Transaction.Current == null | ||
&& CurrentContext.Context.Database.AutoTransactionsEnabled) | ||
&& transactionEnlistManager?.EnlistedTransaction is null | ||
&& transactionEnlistManager?.CurrentAmbientTransaction is null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note slight behavior change where the connection doesn't implement ITransactionEnlistmentManager but Transaction.Current is non-null. New behavior seems more correct.
If we expose |
390e5cb
to
bb2df4c
Compare
Makes sense, changed HandleAmbientTransactions back to private. |
Hello @roji! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:
These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check. Give feedback on thisFrom the bot dev teamWe've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments. Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin. |
Accessing
Transaction.Current
(in HandleAmbientTransactions) is a heavy operation - profiling shows it to take around 0.3% of the total running time.Npgsql has connection string parameter to disable this check at the ADO level. Allowing providers to override HandleAmbientTransactions would allow EFCore.PG to skip this if the parameter is set.
HandleAmbientTransactions isn't a great name for a publicly-exposed method, but I don't really have anything better...
Related Npgsql PRs: npgsql/efcore.pg#1742, npgsql/npgsql#3570