From cf4d797b796c467d31ca7f07e14e6290b5a6dd75 Mon Sep 17 00:00:00 2001 From: Petru Conduraru Date: Tue, 7 Jul 2026 14:54:44 +0300 Subject: [PATCH] Bonsai: don't crash querying a freshly linked IFC with cache off Link IFC with 'Use Cache' unchecked crashed with FileNotFoundError when no .ifc.cache.blend existed yet (a fresh link). Regression from 35e3d9c42, which refactored the cache-clear guard from 'if not self.use_cache and blend_filepath.exists()' into should_clear_cache() but dropped the existence check on the not-use_cache path, so os.remove() ran on a non-existent file. Check blend_filepath.exists() first in should_clear_cache() so the remove is never attempted when there is nothing to clear, while keeping the query-mismatch cache invalidation intact. Fixes #8350 Co-Authored-By: Claude Opus 4.8 (cherry picked from commit 4a095f98101e2a8d41222ef9aca8f49e5193d216) --- src/bonsai/bonsai/bim/module/project/operator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 8bca415bdf..f416c8ecbd 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1579,10 +1579,13 @@ class LoadLink(bpy.types.Operator, tool.Ifc.Operator): json_filepath = self.filepath_.with_suffix(".ifc.cache.json") def should_clear_cache() -> bool: - if not self.use_cache: - return True + # Nothing to clear if the cache file was never created (e.g. a + # fresh link). Check this first so os.remove below is never + # called on a non-existent path, regardless of use_cache. if not blend_filepath.exists(): return False + if not self.use_cache: + return True data = json.loads(json_filepath.read_text()) # Empty 'query' - model loaded without custom query. # Missing 'query' - model was loaded before custom queries were introduced in Bonsai.