This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 1f6f8688c3e Fix db cleanup logging behavior and docstrings (#58459)
1f6f8688c3e is described below

commit 1f6f8688c3e2a2fa2e6049c57edb15e99cea4029
Author: Jed Cunningham <[email protected]>
AuthorDate: Thu Nov 20 04:06:07 2025 -0700

    Fix db cleanup logging behavior and docstrings (#58459)
    
    Update `_check_for_rows` to avoid unnecessary logging and
    queries when there are no rows, fix a typo in `run_cleanup
    docstring`, and correct `_suppress_with_logging` docstring.
    
    Co-authored-by: Ian Buss <[email protected]>
---
 airflow-core/src/airflow/utils/db_cleanup.py | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/airflow-core/src/airflow/utils/db_cleanup.py 
b/airflow-core/src/airflow/utils/db_cleanup.py
index 18b7413f64d..558146fc84d 100644
--- a/airflow-core/src/airflow/utils/db_cleanup.py
+++ b/airflow-core/src/airflow/utils/db_cleanup.py
@@ -166,13 +166,14 @@ config_dict: dict[str, _TableConfig] = {x.orm_model.name: 
x for x in sorted(conf
 def _check_for_rows(*, query: Query, print_rows: bool = False) -> int:
     num_entities = query.count()
     print(f"Found {num_entities} rows meeting deletion criteria.")
-    if print_rows:
-        max_rows_to_print = 100
-        if num_entities > 0:
-            print(f"Printing first {max_rows_to_print} rows.")
-        logger.debug("print entities query: %s", query)
-        for entry in query.limit(max_rows_to_print):
-            print(entry.__dict__)
+    if not print_rows or num_entities == 0:
+        return num_entities
+
+    max_rows_to_print = 100
+    print(f"Printing first {max_rows_to_print} rows.")
+    logger.debug("print entities query: %s", query)
+    for entry in query.limit(max_rows_to_print):
+        print(entry.__dict__)
     return num_entities
 
 
@@ -422,11 +423,7 @@ def _print_config(*, configs: dict[str, _TableConfig]) -> 
None:
 
 @contextmanager
 def _suppress_with_logging(table: str, session: Session):
-    """
-    Suppresses errors but logs them.
-
-    Also stores the exception instance so it can be referred to after exiting 
context.
-    """
+    """Suppresses errors but logs them."""
     try:
         yield
     except (OperationalError, ProgrammingError):
@@ -519,7 +516,7 @@ def run_cleanup(
     :param dry_run: If true, print rows meeting deletion criteria
     :param verbose: If true, may provide more detailed output.
     :param confirm: Require user input to confirm before processing deletions.
-    :param skip_archive: Set to True if you don't want the purged rows 
preservied in an archive table.
+    :param skip_archive: Set to True if you don't want the purged rows 
preserved in an archive table.
     :param session: Session representing connection to the metadata database.
     :param batch_size: Maximum number of rows to delete or archive in a single 
transaction.
     """

Reply via email to