diff --git a/invokeai/app/services/config.py b/invokeai/app/services/config.py index a3508e11ba..a9a4a64f75 100644 --- a/invokeai/app/services/config.py +++ b/invokeai/app/services/config.py @@ -274,7 +274,7 @@ class InvokeAISettings(BaseSettings): @classmethod def _excluded(self) -> List[str]: # internal fields that shouldn't be exposed as command line options - return ["type", "initconf"] + return ["type", "initconf", "cached_root"] @classmethod def _excluded_from_yaml(self) -> List[str]: @@ -290,6 +290,7 @@ class InvokeAISettings(BaseSettings): "restore", "root", "nsfw_checker", + "cached_root", ] class Config: @@ -423,6 +424,7 @@ class InvokeAIAppConfig(InvokeAISettings): log_level : Literal[tuple(["debug","info","warning","error","critical"])] = Field(default="info", description="Emit logging messages at this level or higher", category="Logging") version : bool = Field(default=False, description="Show InvokeAI version and exit", category="Other") + cached_root : Path = Field(default=None, description="internal use only", category="DEPRECATED") # fmt: on def parse_args(self, argv: List[str] = None, conf: DictConfig = None, clobber=False): @@ -470,10 +472,15 @@ class InvokeAIAppConfig(InvokeAISettings): """ Path to the runtime root directory """ - if self.root: - return Path(self.root).expanduser().absolute() + # we cache value of root to protect against it being '.' and the cwd changing + if self.cached_root: + root = self.cached_root + elif self.root: + root = Path(self.root).expanduser().absolute() else: - return self.find_root() + root = self.find_root() + self.cached_root = root + return self.cached_root @property def root_dir(self) -> Path: