jedcunningham commented on code in PR #51472:
URL: https://github.com/apache/airflow/pull/51472#discussion_r2132408437
##########
airflow-core/src/airflow/utils/db.py:
##########
@@ -980,6 +980,27 @@ def synchronize_log_template(*, session: Session =
NEW_SESSION) -> None:
session.add(LogTemplate(filename=filename,
elasticsearch_id=elasticsearch_id))
+def delete_import_errors(*, session: Session) -> None:
+ """
+ Delete all import errors from the database after migrations.
+
+ This is used to clean up the `ParseImportError` table after migrations
+ since the old import errors will not have bundle_name value
+ """
+ from sqlalchemy import delete
+
+ from airflow.models.errors import ParseImportError
+
+ metadata = reflect_tables([ParseImportError], session)
+ parse_import_error_table: Table | None =
metadata.tables.get(ParseImportError.__tablename__)
+
+ if parse_import_error_table is None:
+ log.info("ParseImportError table does not exist; Strange! skipping
import error cleanup.")
+ return
+ # Select all rows where bundle_name is NULL
+
session.execute(delete(parse_import_error_table).where(parse_import_error_table.c.bundle_name.is_(None)))
Review Comment:
I feel like we should do this in [this
migration](https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/migrations/versions/0050_3_0_0_add_dagbundlemodel.py)
instead of carrying this around forever.
Granted, it doesn't help already upgraded deployments, but I think it's
better to keep it scoped there long term.
--
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]