fix: Fix Ruff PERF403 and add cache_dir validator

- Convert dictionary comprehension in setup.py to fix PERF403
- Add cache_dir validator to normalize paths like config_dir
- Follows CodeRabbit review feedback
This commit is contained in:
阳虎
2026-03-25 21:41:13 +08:00
parent 38bf3ec6e2
commit c8610fb4ce
2 changed files with 25 additions and 4 deletions

View File

@ -62,10 +62,11 @@ from langflow.services.deps import (
def update_projects_components_with_latest_component_versions(project_data, all_types_dict):
# Flatten the all_types_dict for easy access
all_types_dict_flat = {}
for category in all_types_dict.values():
for key, component in category.items():
all_types_dict_flat[key] = component
all_types_dict_flat = {
key: component
for category in all_types_dict.values()
for key, component in category.items()
}
node_changes_log = defaultdict(list)
project_data_copy = deepcopy(project_data)

View File

@ -509,6 +509,26 @@ class Settings(BaseSettings):
return str(value)
@field_validator("cache_dir", mode="before")
@classmethod
def validate_cache_dir(cls, value):
"""Validate and normalize cache_dir path.
If not set, returns None and the factory will fall back to config_dir.
If set, resolves to an absolute path and creates the directory if needed.
"""
if not value:
return None
if isinstance(value, str):
value = Path(value)
# Resolve to absolute path to handle relative paths correctly
value = value.resolve()
if not value.exists():
value.mkdir(parents=True, exist_ok=True)
return str(value)
@field_validator("database_url", mode="before")
@classmethod
def set_database_url(cls, value, info):