Correct the retry_db_transaction docstring about provide_session - #71311
Open
1fanwang wants to merge 1 commit into
Open
Correct the retry_db_transaction docstring about provide_session#713111fanwang wants to merge 1 commit into
1fanwang wants to merge 1 commit into
Conversation
The docstring says the decorator should not be used with @provide_session, but three call sites in airflow-core stack the two, and the combination is the only way to retry a read that needs a session created for it. The real constraint is ordering. The retry wrapper looks up the session when it runs, so it has to sit inside @provide_session; the opposite order raises TypeError because no session exists yet. Signed-off-by: 1fanwang <1fannnw@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
retry_db_transaction's docstring says:Three call sites in
airflow-coredo exactly that, and have for years:renderedtifields.py:241dagwarning.py:78manager.py:701Why it matters
The guidance is the opposite of what the code requires, so a contributor who follows it either avoids a valid pattern or stacks the decorators the one way that breaks. That combination is also the only way to retry a read whose session is created for it, which is what those three call sites need. The wording has been there since the decorator landed in #14109 (2021).
What the constraint actually is
Ordering, not incompatibility. The retry wrapper resolves
sessionfrom the call's arguments when it runs (retries.py:91-96) and rolls it back between attempts, so the session must already be bound.@provide_sessiontherefore goes on the outside. The docstring now says that and shows the shape.Testing Done
Both orderings, against a real SQLAlchemy session, on a clean checkout of
main:The documented order works and returns the queried value. The order the old docstring implied fails at call time with the
TypeErrorraised atretries.py:96.Docstring-only change, so there is no behavior to regress and no test added.