iting0321 commented on code in PR #64838:
URL: https://github.com/apache/airflow/pull/64838#discussion_r3067765313


##########
airflow-core/src/airflow/migrations/versions/0017_2_9_2_fix_inconsistency_between_ORM_and_migration_files.py:
##########
@@ -76,9 +78,9 @@ def upgrade():
     elif conn.dialect.name == "sqlite":
         # SQLite does not support DROP CONSTRAINT
         # We have to recreate the table without the constraint
-        conn.execute(sa.text("PRAGMA foreign_keys=off"))

Review Comment:
   ```python
   def disable_sqlite_fkeys(op):
       if get_dialect_name(op) == "sqlite":
           with contextlib.ExitStack() as exit_stack:
               op.execute("PRAGMA foreign_keys=off")
               exit_stack.callback(op.execute, "PRAGMA foreign_keys=on")
               yield op
       else:
           yield op
   ```
   The if `get_dialect_name(op) == "sqlite"` check inside 
`disable_sqlite_fkeys` is necessary. The function is designed to be called 
unconditionally on all dialects.
   For example, in 
[0082_3_1_0_make_bundle_name_not_nullable.py](https://github.com/apache/airflow/pull/64838/changes/BASE..28e328cf4f242cf7173acc0b03a3bec868a28dc7#diff-aa50016470776e169fff06e0c03fae310ba5cfe3e96cd977e55aa9f6915d09a7R65)
 line 65.
   Use it without a surrounding if `dialect_name == "sqlite"`  guard. Without 
the internal check, the function would attempt to execute `PRAGMA 
foreign_keys=off` on mysql or PostgreSQL, which would fail.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to