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/02/03 04:24:58 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #21283: Cleanup session.commit() when @provide_session decorator is used

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