uranusjr commented on code in PR #51336:
URL: https://github.com/apache/airflow/pull/51336#discussion_r2122392185
##########
airflow-core/src/airflow/migrations/utils.py:
##########
@@ -103,3 +103,20 @@ def mysql_drop_index_if_exists(index_name, table_name, op):
SELECT 1;
END IF;
""")
+
+
+def _sqlite_guarded_drop_constraint(
+ *,
+ table: str,
+ key: str,
+ type_: str,
+ op,
+) -> None:
+ conn = op.get_bind()
+ dialect_name = conn.dialect.name
+ try:
+ with op.batch_alter_table(table, schema=None) as batch_op:
+ batch_op.drop_constraint(key, type_=type_)
+ except ValueError:
+ if dialect_name != "sqlite":
+ raise
Review Comment:
I assumed we can’t be more specific than ValueError? (This is too vague to
my liking.)
I wonder if it would read better if we implement this like this instead:
```python
def ignore_sqlite_valueerror():
from alembic import op
if op.get_bind().dialect.name == "sqlite":
return contextlib.suppress(ValueError)
return contextlib.nullcontext()
# And in migrations...
with ignore_sqlite_valueerror(), op.batch_alter_table(...) as batch_op:
batch_op.drop_constraint(...)
```
--
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]