chore: Add cleanup step for old UDFs in anonymous dataset#2171
Merged
chore: Add cleanup step for old UDFs in anonymous dataset#2171
Conversation
bigframes/blob/_functions.py
Outdated
Comment on lines
81
to
97
| def _cleanup_old_udfs(self): | ||
| """Clean up old UDFs in the anonymous dataset.""" | ||
| dataset = self._session._anon_dataset_manager.dataset | ||
| routines = list(self._session.bqclient.list_routines(dataset)) | ||
| cleanup_cutoff_time = datetime.datetime.now( | ||
| datetime.timezone.utc | ||
| ) - datetime.timedelta(days=_UDF_CLEANUP_THRESHOLD_DAYS) | ||
|
|
||
| for routine in routines: | ||
| if ( | ||
| routine.created < cleanup_cutoff_time | ||
| and routine._properties["routineType"] == "SCALAR_FUNCTION" | ||
| ): | ||
| try: | ||
| self._session.bqclient.delete_routine(routine.reference) | ||
| except Exception: | ||
| pass |
Contributor
There was a problem hiding this comment.
Seems this code should just be in the AnonymousDatasetManager itself? Also, are we sure on the timing of when we want to trigger this?
Contributor
Author
There was a problem hiding this comment.
Moved to AnonymousDatasetManager.
Contributor
TrevorBergeron
left a comment
There was a problem hiding this comment.
Also, maybe some tests to validate the behavior?
Contributor
Author
Added a test for it. |
Comment on lines
+180
to
+185
| except Exception as e: | ||
| # Log a warning on the failure, do not interrupt the workflow. | ||
| msg = bfe.format_message( | ||
| f"Failed to clean up the old Python UDFs before closing the session: {e}" | ||
| ) | ||
| warnings.warn(msg, category=bfe.CleanupFailedWarning) |
Contributor
There was a problem hiding this comment.
This will only be warned if the list_routines call fails, but if all the individual deletions fail, we won't warn?
TrevorBergeron
approved these changes
Nov 6, 2025
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.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes b/450913424 🦕