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 06:40:10 UTC

[GitHub] [airflow] ephraimbuddy opened a new pull request #20096: Fix mypy issues in www/views.py

ephraimbuddy opened a new pull request #20096:
URL: https://github.com/apache/airflow/pull/20096


   This PR fixes the mypy issues in views.py
   
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


-- 
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 pull request #20096: Fix mypy issues in www/views.py

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


   There's a test in the AWS provider failing, not sure if it's related to the AWS outage today. Likely not related 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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       I guess w need my new fancy toy then!
   
   ```python
   class SessionMaker(Protocol):
       """Fake the type returned by sessionmaker for typg hints.
   
       Add more things to this class as we need them.
       """
   
       bind: Engine
   
       def __call__(self, **kwargs: Any) -> SASession:
           ...
   
       def remove(self) -> None:
           ...
   
   
   Session: SessionMaker
   ```

##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       I guess we need my new fancy toy then!
   
   ```python
   class SessionMaker(Protocol):
       """Fake the type returned by sessionmaker for typg hints.
   
       Add more things to this class as we need them.
       """
   
       bind: Engine
   
       def __call__(self, **kwargs: Any) -> SASession:
           ...
   
       def remove(self) -> None:
           ...
   
   
   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] uranusjr commented on a change in pull request #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +544,8 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        session: sqlalchemy.orm.session.Session = settings.Session
+        extra_args['sqlite_warning'] = session.bind.dialect.name == 'sqlite'

Review comment:
       Although it is likely better to fix this in `settings` instead since I’d expect this very issue to pop up for other modules.
   
   I think changing `Session: Optional[SASession] = None` there to just `Session: SASession` would fix the issue.

##########
File path: airflow/www/views.py
##########
@@ -30,12 +30,13 @@
 from functools import wraps
 from json import JSONDecodeError
 from operator import itemgetter
-from typing import Any, Callable, List, Optional, Set, Tuple, Union
+from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
 from urllib.parse import parse_qsl, unquote, urlencode, urlparse
 
 import lazy_object_proxy
 import markupsafe
 import nvd3
+import sqlalchemy
 import sqlalchemy as sqla

Review comment:
       There’s already an alias imported so you can use `sqla` for where you’re using `sqlalchemy` and onmit the import addition.




-- 
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] ephraimbuddy commented on a change in pull request #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       mypy is complaining for callable:
   ```
   airflow/www/views.py:546: error: "Callable[..., Any]" has no
   attribute "bind"
       ... extra_args['sqlite_warning'] = settings.Session.bind...
                                          ^
   Found 1 error in 1 file (checked 1 source file)
   ```




-- 
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] ephraimbuddy commented on pull request #20096: Fix mypy issues in www/views.py

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


   This looks good now. Let me know if I should merge. @uranusjr 


-- 
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] ephraimbuddy commented on a change in pull request #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +544,8 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        session: sqlalchemy.orm.session.Session = settings.Session
+        extra_args['sqlite_warning'] = session.bind.dialect.name == 'sqlite'

Review comment:
       Ok. I will try it




-- 
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] ephraimbuddy commented on a change in pull request #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       Nice. Updated with settings.engine




-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +543,7 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        extra_args['sqlite_warning'] = settings.engine.bind.dialect.name == 'sqlite'

Review comment:
       ```suggestion
           extra_args['sqlite_warning'] = settings.engine.dialect.name == 'sqlite'
   ```
   
   I think Mypy will complain None does not have attribute dialect though. Consider the protocol approach, please?




-- 
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 #20096: Fix mypy issues in www/views.py

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


   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 merged pull request #20096: Fix mypy issues in www/views.py

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


   


-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +543,7 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        extra_args['sqlite_warning'] = settings.engine.bind.dialect.name == 'sqlite'

Review comment:
       Yeah, I made it non-optional in my models.dag mypy PR.




-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       Let’s use the `Callable` form (it’s done after a discussion in another PR)




-- 
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] ephraimbuddy commented on pull request #20096: Fix mypy issues in www/views.py

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


   Done. @uranusjr you can also take another look as I changed what you recently merged


-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       I guess w need my new fancy toy then!
   
   ```python
   class SessionMaker(Protocol):
       """Fake the type returned by sessionmaker for typg hints.
   
       Add more things to this class as we need them.
       """
   
       bind: Engine
   
       def __call__(self, **kwargs: Any) -> SASession:
           ...
   
       def remove(self) -> None:
           ...
   ```




-- 
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 #20096: Fix mypy issues in www/views.py

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


   Needs conflict resolution @ephraimbuddy 


-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +543,7 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        extra_args['sqlite_warning'] = settings.engine.bind.dialect.name == 'sqlite'

Review comment:
       ```suggestion
           extra_args['sqlite_warning'] = settings.engine.dialect.name == 'sqlite'
   ```




-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       Or change usages of `settings.Session.bind` to `settings.engine`




-- 
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 #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/settings.py
##########
@@ -80,7 +80,7 @@
 DAGS_FOLDER: str = os.path.expanduser(conf.get('core', 'DAGS_FOLDER'))
 
 engine: Optional[Engine] = None
-Session: Callable[..., SASession]
+Session: SASession

Review comment:
       The downside of `settings.engine` is it’s an `Optional`. Pick your poision I guess :p




-- 
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] ephraimbuddy commented on a change in pull request #20096: Fix mypy issues in www/views.py

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



##########
File path: airflow/www/views.py
##########
@@ -543,7 +543,7 @@ class AirflowBaseView(BaseView):
     }
 
     if not conf.getboolean('core', 'unit_test_mode'):
-        extra_args['sqlite_warning'] = settings.Session.bind.dialect.name == 'sqlite'
+        extra_args['sqlite_warning'] = settings.engine.bind.dialect.name == 'sqlite'

Review comment:
       The engine is no longer optional. A change made in another PR, so let's see what happens




-- 
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