You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ephraimbuddy (via GitHub)" <gi...@apache.org> on 2025/06/06 18:26:57 UTC

Re: [PR] Clean up import error records during DB migration [airflow]

ephraimbuddy commented on code in PR #51472:
URL: https://github.com/apache/airflow/pull/51472#discussion_r2132665711


##########
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:
   Done



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