Skip to content

Commit 3c7271f

Browse files
github-actions[bot]jedcunninghamianbuss
authored andcommitted
[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 1f6f868) Co-authored-by: Jed Cunningham <[email protected]> Co-authored-by: Ian Buss <[email protected]>
1 parent 8eee5ee commit 3c7271f

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

airflow-core/src/airflow/utils/db_cleanup.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,14 @@ def readable_config(self):
166166
def _check_for_rows(*, query: Query, print_rows: bool = False) -> int:
167167
num_entities = query.count()
168168
print(f"Found {num_entities} rows meeting deletion criteria.")
169-
if print_rows:
170-
max_rows_to_print = 100
171-
if num_entities > 0:
172-
print(f"Printing first {max_rows_to_print} rows.")
173-
logger.debug("print entities query: %s", query)
174-
for entry in query.limit(max_rows_to_print):
175-
print(entry.__dict__)
169+
if not print_rows or num_entities == 0:
170+
return num_entities
171+
172+
max_rows_to_print = 100
173+
print(f"Printing first {max_rows_to_print} rows.")
174+
logger.debug("print entities query: %s", query)
175+
for entry in query.limit(max_rows_to_print):
176+
print(entry.__dict__)
176177
return num_entities
177178

178179

@@ -422,11 +423,7 @@ def _print_config(*, configs: dict[str, _TableConfig]) -> None:
422423

423424
@contextmanager
424425
def _suppress_with_logging(table: str, session: Session):
425-
"""
426-
Suppresses errors but logs them.
427-
428-
Also stores the exception instance so it can be referred to after exiting context.
429-
"""
426+
"""Suppresses errors but logs them."""
430427
try:
431428
yield
432429
except (OperationalError, ProgrammingError):
@@ -519,7 +516,7 @@ def run_cleanup(
519516
:param dry_run: If true, print rows meeting deletion criteria
520517
:param verbose: If true, may provide more detailed output.
521518
:param confirm: Require user input to confirm before processing deletions.
522-
:param skip_archive: Set to True if you don't want the purged rows preservied in an archive table.
519+
:param skip_archive: Set to True if you don't want the purged rows preserved in an archive table.
523520
:param session: Session representing connection to the metadata database.
524521
:param batch_size: Maximum number of rows to delete or archive in a single transaction.
525522
"""

0 commit comments

Comments
 (0)