Skip to content

fix: cache handling in SmashConfig due to invalid path exception#598

Merged
davidberenstein1957 merged 3 commits intoPrunaAI:mainfrom
ParagEkbote:fix-cache-cleanup-issue
Apr 2, 2026
Merged

fix: cache handling in SmashConfig due to invalid path exception#598
davidberenstein1957 merged 3 commits intoPrunaAI:mainfrom
ParagEkbote:fix-cache-cleanup-issue

Conversation

@ParagEkbote
Copy link
Copy Markdown
Contributor

@ParagEkbote ParagEkbote commented Mar 26, 2026

Description

As described in the issue, if path becomes None or invalid in self.cache_dir, the following exception is raised:

Exception ignored in: <function SmashConfig.__del__ at 0x71ae64ee5e40> Traceback (most recent call last): File "/teamspace/studios/this_studio/pruna/src/pruna/config/smash_config.py", line 200, in __del__ File "/teamspace/studios/this_studio/pruna/src/pruna/config/smash_config.py", line 220, in cleanup_cache_dir File "/system/conda/miniconda3/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 860, in exists File "/system/conda/miniconda3/uv/python/cpython-3.12.13-linux-x86_64-gnu/lib/python3.12/pathlib.py", line 840, in stat AttributeError: 'NoneType' object has no attribute 'stat'

To fix this issue, I made cleanup_cache_dir more robust by adding runtime safety guards and corrected cache directory initialization to consistently use self.cache_dir_prefix within SmashConfig. Could you please review?

cc: @davidberenstein1957

Related Issue

Fixes #408

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

@davidberenstein1957 davidberenstein1957 self-requested a review April 1, 2026 09:10
Comment on lines +221 to +227
if (
hasattr(self, "cache_dir")
and self.cache_dir is not None
and isinstance(self.cache_dir, Path)
and self.cache_dir.exists()
):
shutil.rmtree(self.cache_dir, ignore_errors=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if self.cache_dir is not a path? Can we first also see if we can convert it to a Path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could update the handling of self.cache dir to first try converting to a Path and raise an error if the conversion is not correct.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I feel that this might make sense if gor some reason someone passes a str or something?

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@davidberenstein1957 davidberenstein1957 merged commit 38d76da into PrunaAI:main Apr 2, 2026
4 checks passed
@davidberenstein1957
Copy link
Copy Markdown
Member

Thanks. @ParagEkbote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Silent bug in Eval Agent

2 participants