You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/07 11:49:09 UTC

[GitHub] [airflow] uranusjr opened a new pull request #20104: Helper for provide_session-decorated functions

uranusjr opened a new pull request #20104:
URL: https://github.com/apache/airflow/pull/20104


   This can be used like this:
   
   ```python
   @provide_session
   def some_function(arg1, arg2, session: Session = NEW_SESSION) -> None:
       session.query(Model)...
   ```
   
   This eliminates the need to use `Optional[Session] = None` to reduce boilerplate code.
   
   cc @potiuk this can be useful for your #19914.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763967061



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       This will conflict with https://github.com/apache/airflow/pull/20000 (and also , the SessionMaker is both callable, _and_ behaves like an actual Session. SQLA is weird like that)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763968389



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       This might be fine though




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763971666



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       Let me see if I can just make this `Session: SessionMaker`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#issuecomment-987854027


   OH NICE!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb merged pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
ashb merged pull request #20104:
URL: https://github.com/apache/airflow/pull/20104


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763974125



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       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.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#issuecomment-987856327


   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763984969



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       This is probably fine as it is (and it's how we use it in Airflow)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #20104: Helper for provide_session-decorated functions

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #20104:
URL: https://github.com/apache/airflow/pull/20104#discussion_r763981620



##########
File path: airflow/settings.py
##########
@@ -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]

Review comment:
       Oh actually :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org