fix: resolve logging.py issues from code audit - #255
Closed
fwh888 wants to merge 1 commit into
Closed
Conversation
Three fixes in rdsa_utils/logging.py: 1. & -> and operator (line 237): Changed bitwise AND to logical AND in show_records & stop_pipeline condition. 2. try/finally for cache cleanup (log_rows_in_spark_df): Moved kwargs['df'].unpersist() into a finally block so the input DataFrame cache is always released, even if the decorated function raises an exception. Prevents Spark cache leak / OOM. 3. Added isinstance check before unpersist to avoid AttributeError when kwargs['df'] is not a Spark DataFrame. See issue ONSdigital#254 for full audit report.
Collaborator
|
Closed, as we do not accept submissions from users outside the ONS and I suspect this may be an LLM. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issues found during a code audit of the core rdsa-utils modules (see issue #254).
Changes
1. Bitwise AND → Logical AND (logging.py:237)
Bitwise
&on boolean values works accidentally but is not Pythonic and will behave unexpectedly with non-standard boolean types (e.g.,numpy.bool_).2. try/finally for Spark cache cleanup (log_rows_in_spark_df)
If the decorated function raises an exception, the input DataFrame's cache was never released, causing a persistent Spark memory leak. Added a type guard to avoid AttributeError on non-DataFrame inputs.
Remaining issues from audit
See issue #254 for the full audit report. Other findings (handler validation order, logger init idempotency, MEMORY_ONLY → MEMORY_AND_DISK) are higher-risk changes that require more careful review.