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


##########
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:
   Consider adding a session.commit() after executing the deletion query if the 
changes are not automatically committed, or ensure that the calling context 
handles committing these changes.
   ```suggestion
       
session.execute(delete(parse_import_error_table).where(parse_import_error_table.c.bundle_name.is_(None)))
       session.commit()
   ```



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