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 2020/05/20 23:49:00 UTC

[GitHub] [airflow] mik-laj opened a new pull request #8940: Remove side-effect of session in FAB

mik-laj opened a new pull request #8940:
URL: https://github.com/apache/airflow/pull/8940


   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [X] Description above provides context of the change
   - [X] Unit tests coverage for changes (not needed for documentation changes)
   - [X] Target Github ISSUE in description if exists
   - [X] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [X] Relevant documentation is updated including usage instructions.
   - [X] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   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/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428370876



##########
File path: airflow/www/app.py
##########
@@ -70,8 +70,9 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
     app.json_encoder = AirflowJsonEncoder
 
     csrf.init_app(app)
-
-    db = SQLA(app)
+    db = SQLA()

Review comment:
       This creates a new session, but we want to use your global session instead of creating another session.
   https://github.com/pallets/flask-sqlalchemy/blob/706982bb8a096220d29e5cef156950237753d89f/flask_sqlalchemy/__init__.py#L714




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

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



[GitHub] [airflow] mik-laj commented on pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#issuecomment-631815639


   I need this change to integrate connexion with 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.

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428372645



##########
File path: airflow/www/app.py
##########
@@ -95,9 +96,18 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
                 """Your CUSTOM_SECURITY_MANAGER must now extend AirflowSecurityManager,
                  not FAB's security manager.""")
 
-        appbuilder = AppBuilder(
-            app,
-            db.session if not session else session,
+        class AirflowAppBuilder(AppBuilder):
+
+            def add_view(self, baseview, *args, **kwargs):
+                if hasattr(baseview, 'datamodel'):
+                    # Delete sessions if initiated previously to limit side effects. We want to use
+                    # the current session in the current application.
+                    baseview.datamodel.session = None

Review comment:
       The session is saved to the object, which is an attribute of the class (not instance), so we have a huge side effect.
   https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/base.py#L339-L347
   https://github.com/apache/airflow/blob/df159826d61a934862e9fe6a62b535eb443e5710/airflow/www/views.py#L2309




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

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



[GitHub] [airflow] mik-laj merged pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #8940:
URL: https://github.com/apache/airflow/pull/8940


   


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

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



[GitHub] [airflow] mik-laj commented on pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#issuecomment-700771485


   It wasn't a quick fix when I first encountered it. It took me almost a week of work to fix this problem in Airflow 2.0 when I was working on the API.


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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428372980



##########
File path: airflow/www/app.py
##########
@@ -272,10 +282,6 @@ def apply_caching(response):
                 response.headers["X-Frame-Options"] = "DENY"
             return response
 
-        @app.teardown_appcontext

Review comment:
       This is now handled correctly by the flask-sqlalchemy library.
   https://github.com/pallets/flask-sqlalchemy/blob/706982bb8a096220d29e5cef156950237753d89f/flask_sqlalchemy/__init__.py#L840-L847




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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428373315



##########
File path: airflow/www/app.py
##########
@@ -46,7 +46,7 @@
 log = logging.getLogger(__name__)
 
 
-def create_app(config=None, session=None, testing=False, app_name="Airflow"):

Review comment:
       session parameter is not used anymore.




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

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



[GitHub] [airflow] ashb commented on a change in pull request #8940: Remove side-effect of session in FAB

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



##########
File path: airflow/www/app.py
##########
@@ -95,9 +96,18 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
                 """Your CUSTOM_SECURITY_MANAGER must now extend AirflowSecurityManager,
                  not FAB's security manager.""")
 
-        appbuilder = AppBuilder(
-            app,
-            db.session if not session else session,
+        class AirflowAppBuilder(AppBuilder):
+
+            def add_view(self, baseview, *args, **kwargs):
+                if hasattr(baseview, 'datamodel'):
+                    # Delete sessions if initiated previously to limit side effects. We want to use
+                    # the current session in the current application.
+                    baseview.datamodel.session = None

Review comment:
       Oh, i remember what my problem was: date columns on FABs own security models.




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

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



[GitHub] [airflow] ashb commented on a change in pull request #8940: Remove side-effect of session in FAB

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



##########
File path: airflow/www/app.py
##########
@@ -95,9 +96,18 @@ def create_app(config=None, session=None, testing=False, app_name="Airflow"):
                 """Your CUSTOM_SECURITY_MANAGER must now extend AirflowSecurityManager,
                  not FAB's security manager.""")
 
-        appbuilder = AppBuilder(
-            app,
-            db.session if not session else session,
+        class AirflowAppBuilder(AppBuilder):
+
+            def add_view(self, baseview, *args, **kwargs):
+                if hasattr(baseview, 'datamodel'):
+                    # Delete sessions if initiated previously to limit side effects. We want to use
+                    # the current session in the current application.
+                    baseview.datamodel.session = None

Review comment:
       I think I had to work around this (or at least it bit me) when I was doing the TZ work in the UI
   
   :+1:




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

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



[GitHub] [airflow] mik-laj removed a comment on pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj removed a comment on pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#issuecomment-700771485


   It wasn't a quick fix when I first encountered it. It took me almost a week of work to fix this problem in Airflow 2.0 when I was working on the API.


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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428373704



##########
File path: tests/www/test_views.py
##########
@@ -428,7 +428,7 @@ def prepare_dagruns(self):
             state=State.RUNNING)
 
     def test_index(self):
-        with assert_queries_count(5):
+        with assert_queries_count(37):

Review comment:
       Queries from FAB Security are also now included.




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

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



[GitHub] [airflow] mik-laj commented on a change in pull request #8940: Remove side-effect of session in FAB

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #8940:
URL: https://github.com/apache/airflow/pull/8940#discussion_r428372980



##########
File path: airflow/www/app.py
##########
@@ -272,10 +282,6 @@ def apply_caching(response):
                 response.headers["X-Frame-Options"] = "DENY"
             return response
 
-        @app.teardown_appcontext

Review comment:
       This is now handled correctly by the flask-sqlalchemy library.
   https://github.com/pallets/flask-sqlalchemy/blob/master/flask_sqlalchemy/__init__.py#L840-L847




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

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