{"record":{"id":"faf8313f95e2d332","repo":"windmill-labs/windmill","slug":"state-path-not-found","errorCode":null,"errorMessage":"State path not found","messagePattern":"State path not found","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"python-client/wmill/wmill/client.py","lineNumber":1220,"sourceCode":"        \"\"\"Get the current user information (alias for whoami).\n\n        Returns:\n            User details dictionary\n        \"\"\"\n        return self.whoami()\n\n    @property\n    def state_path(self) -> str:\n        \"\"\"Get the state resource path from environment.\n\n        Returns:\n            State path string\n        \"\"\"\n        state_path = os.environ.get(\n            \"WM_STATE_PATH_NEW\", os.environ.get(\"WM_STATE_PATH\")\n        )\n        if state_path is None:\n            raise Exception(\"State path not found\")\n        return state_path\n\n    @property\n    def state(self) -> Any:\n        \"\"\"Get the workflow state.\n\n        Returns:\n            State value or None if not set\n        \"\"\"\n        return self.get_resource(path=self.state_path, none_if_undefined=True, interpolated=True)\n\n    @state.setter\n    def state(self, value: Any) -> None:\n        \"\"\"Set the workflow state.\"\"\"\n        self.set_state(value)\n\n    @staticmethod\n    def set_shared_state_pickle(value: Any, path: str = \"state.pickle\") -> None:","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/python-client/wmill/wmill/client.py#L1202-L1238","documentation":"The state_path property reads the job's state directory from WM_STATE_PATH_NEW (falling back to legacy WM_STATE_PATH). Windmill sets these only inside running flow jobs that carry state; anywhere else the variable is absent and this exception is raised.","triggerScenarios":"Accessing wm.state_path / wm.state from a standalone script, a non-flow job type, a run outside the Windmill worker, or an environment where neither env var is set.","commonSituations":"Testing flow-state code by running the script locally or as a plain script instead of inside a flow; older workers that never set WM_STATE_PATH_NEW.","solutions":["Run the script as a step inside a real flow run (state only exists there)","Use full flow preview in the flow editor, which sets the env vars","Guard access: check os.environ.get('WM_STATE_PATH_NEW') or os.environ.get('WM_STATE_PATH') first","Use workspace variables or S3 files for persistence outside flows"],"exampleFix":"// before\npath = wmill.get_client().state_path\n// after\nimport os\nif os.environ.get(\"WM_STATE_PATH_NEW\") or os.environ.get(\"WM_STATE_PATH\"):\n    path = wmill.get_client().state_path\nelse:\n    path = None  # not inside a stateful flow run","handlingStrategy":"validation","validationCode":"import os\ndef has_state_context() -> bool:\n    return bool(os.environ.get(\"WM_STATE_PATH_NEW\") or os.environ.get(\"WM_STATE_PATH\"))","typeGuard":null,"tryCatchPattern":"try:\n    path = client.state_path\nexcept Exception:\n    path = None  # not inside a stateful flow run; use alternative persistence","preventionTips":["Only use state_path/state inside flow steps","Check the env vars before touching state APIs","Use workspace variables or S3 files for persistence in standalone scripts","Test state logic with full flow preview, not step preview"],"tags":["environment-variable","flow","state","context"],"backgroundTag":"missing-env-var","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}