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

ephraimanierobi pushed a commit to branch v3-1-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-1-test by this push:
     new 4104418d44b [v3-1-test] Fix db cleanup logging behavior and docstrings 
(#58459) (#58523)
4104418d44b is described below

commit 4104418d44b7e7a03fd98f79faa1a19f609890f0
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Nov 20 15:45:48 2025 +0100

    [v3-1-test] Fix db cleanup logging behavior and docstrings (#58459) (#58523)
    
    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.
    (cherry picked from commit 1f6f8688c3e2a2fa2e6049c57edb15e99cea4029)
    
    Co-authored-by: Jed Cunningham 
<[email protected]>
    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 5dae8dbe847..3078973e87d 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