-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Helper for provide_session-decorated functions #20104
Conversation
dd307a5
to
70b2a53
Compare
OH NICE! |
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
2fe0f95
to
33f4447
Compare
@@ -77,7 +80,7 @@ | |||
DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER')) | |||
|
|||
engine: Optional[Engine] = None | |||
Session: Optional[SASession] = None | |||
Session: Callable[..., SASession] |
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.
This will conflict with #20000 (and also , the SessionMaker is both callable, and behaves like an actual Session. SQLA is weird like that)
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.
This might be fine though
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.
Let me see if I can just make this Session: SessionMaker
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.
Hmm no, SQLAlchemy is not type hinted well enough, annotating this as sessionmaker
would make Session()
return Any
. I’ll keep this for now since this is more useful in general.
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.
Oh actually :)
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.
This is probably fine as it is (and it's how we use it in Airflow)
* Helper for provide_session-decorated functions * Apply NEW_SESSION trick on XCom (cherry picked from commit a80ac1e)
* Helper for provide_session-decorated functions * Apply NEW_SESSION trick on XCom (cherry picked from commit a80ac1e)
* Helper for provide_session-decorated functions * Apply NEW_SESSION trick on XCom (cherry picked from commit a80ac1e)
This can be used like this:
This eliminates the need to use
Optional[Session] = None
to reduce boilerplate code.cc @potiuk this can be useful for your #19914.