Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances session cleanup by catching ReferenceError for finalized objects and logging any other exceptions during global cleanup.
- Wraps
obj.__exit__in atry/exceptto skip finalized sessions without crashing. - Logs unexpected errors encountered while cleaning up sessions.
Comments suppressed due to low confidence (1)
src/datachain/query/session.py:197
- Add a test case that simulates a finalized
Sessionobject triggering aReferenceErrorto verify that this cleanup path is correctly skipped and logged.
for obj in gc.get_objects(): # Get all tracked objects
| except Exception as e: # noqa: BLE001 | ||
| logger.error(f"Exception while cleaning up session: {e}") # noqa: G004 |
There was a problem hiding this comment.
Catching all exceptions may hide unexpected errors; consider catching more specific exception types or using logger.exception to preserve the full traceback.
| except Exception as e: # noqa: BLE001 | |
| logger.error(f"Exception while cleaning up session: {e}") # noqa: G004 | |
| except Exception: # noqa: BLE001 | |
| logger.exception("Unexpected exception while cleaning up session.") # noqa: G004 |
| if isinstance(obj, Session): | ||
| # Cleanup temp dataset for session variables. | ||
| obj.__exit__(None, None, None) | ||
| except ReferenceError: |
There was a problem hiding this comment.
[nitpick] Consider adding a debug-level log statement here to record when a ReferenceError is caught, which can aid in future troubleshooting.
| except ReferenceError: | |
| except ReferenceError: | |
| logger.debug("ReferenceError caught: Object has already been finalized.") |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1106 +/- ##
==========================================
- Coverage 87.93% 87.90% -0.03%
==========================================
Files 147 147
Lines 12655 12660 +5
Branches 1772 1772
==========================================
+ Hits 11128 11129 +1
- Misses 1091 1095 +4
Partials 436 436
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Caught an error:
While running this simplest script: