Skip to content

Fix FileNotFoundError when validating cache for deleted directories#12015

Open
VitoChenLY wants to merge 1 commit intoComfy-Org:masterfrom
VitoChenLY:fix_filename_cache_bug
Open

Fix FileNotFoundError when validating cache for deleted directories#12015
VitoChenLY wants to merge 1 commit intoComfy-Org:masterfrom
VitoChenLY:fix_filename_cache_bug

Conversation

@VitoChenLY
Copy link

Problem

When calling the /object_info API endpoint, ComfyUI may crash with a FileNotFoundError if a directory that was previously scanned and cached has been manually deleted.

Error Details

FileNotFoundError: [Errno 2] No such file or directory: '/workspace/ComfyUI/models/t5'
  File "folder_paths.py", line 407, in cached_filename_list_
    if os.path.getmtime(folder) != time_modified:

Root Cause

  1. The seed_assets(["models"]) function (introduced in v0.9.2) scans all model directories and caches their structure, including subdirectories like models/t5.
  2. When a directory is scanned, its path and modification time are stored in the global cache (filename_list_cache).
  3. If a user manually deletes a directory (e.g., models/t5) that was previously cached, the cache still contains a reference to it.
  4. When cached_filename_list_() validates the cache by checking directory modification times, it calls os.path.getmtime(folder) on the deleted directory, causing a FileNotFoundError.

Impact

  • Low risk: Only adds exception handling, doesn't change core logic
  • Backward compatible: Existing functionality remains unchanged
  • Improves robustness: Prevents crashes when directories are manually deleted
  • Performance: Minimal impact, only adds a try-except check

@comfy-pr-bot
Copy link
Member

Test Evidence Check

⚠️ Warning: Test Explanation Missing

If this PR modifies behavior that requires testing, a test explanation is required. PRs lacking applicable test explanations may not be reviewed until added. Please add test explanations to ensure code quality and prevent regressions.

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.

You can add it by:

  • GitHub: Drag & drop media directly into the PR description
  • YouTube: Include a link to a short demo

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.

2 participants