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 2022/03/22 17:54:37 UTC

[GitHub] [airflow] chenglongyan opened a new pull request #21283: Cleanup session.commit() when @provide_session decorator is used

chenglongyan opened a new pull request #21283:
URL: https://github.com/apache/airflow/pull/21283


   closes: 
   related: #12818, #12815, #12822
   


-- 
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 #21283: Cleanup session.commit() when @provide_session decorator is used

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



##########
File path: airflow/api_connexion/endpoints/connection_endpoint.py
##########
@@ -125,7 +125,6 @@ def patch_connection(
     for key in data:
         setattr(connection, key, data[key])
     session.add(connection)
-    session.commit()
     return connection_schema.dump(connection)

Review comment:
       This one (and all code similar to this where there’s a `dump` after `commit`) cannot be safely removed. Saving the instance to database can trigger value updates (e.g. autoincrement columns), so `commit` must happen before `dump` to ensure those values are correctly populated.

##########
File path: airflow/cli/commands/connection_command.py
##########
@@ -255,5 +255,4 @@ def _import_helper(file_path):
                 continue
 
             session.add(conn)
-            session.commit()
             print(f'Imported connection {conn_id}')

Review comment:
       Similarly, removing this `commit` will cause the `print` to happen too early, even if data commit does not actually succeed.




-- 
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 #21283: Cleanup session.commit() when @provide_session decorator is used

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



##########
File path: airflow/cli/commands/connection_command.py
##########
@@ -253,7 +254,6 @@ def _import_helper(file_path):
             if session.query(Connection).filter(Connection.conn_id == conn_id).first():
                 print(f'Could not import connection {conn_id}: connection already exists.')
                 continue
-
             session.add(conn)
-            session.commit()
-            print(f'Imported connection {conn_id}')
+            print(f'Load connection {conn_id}')
+    print("Successfully imported all connections.")

Review comment:
       Hmm, I think the previous code is written specifically so if one of the connections fail to import, other previously read connections are still committed to the database (instead of the entire session being rolled back and not committing anything). But I’m not entirely sure which behaviour is more expected by users.




-- 
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] chenglongyan closed pull request #21283: Cleanup session.commit() when @provide_session decorator is used

Posted by GitBox <gi...@apache.org>.
chenglongyan closed pull request #21283:
URL: https://github.com/apache/airflow/pull/21283


   


-- 
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] chenglongyan commented on a change in pull request #21283: Cleanup session.commit() when @provide_session decorator is used

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



##########
File path: airflow/cli/commands/connection_command.py
##########
@@ -253,7 +254,6 @@ def _import_helper(file_path):
             if session.query(Connection).filter(Connection.conn_id == conn_id).first():
                 print(f'Could not import connection {conn_id}: connection already exists.')
                 continue
-
             session.add(conn)
-            session.commit()
-            print(f'Imported connection {conn_id}')
+            print(f'Load connection {conn_id}')
+    print("Successfully imported all connections.")

Review comment:
       -_-| , i will be more careful...




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