{"record":{"id":"e68eea97f3573a60","repo":"pathwaycom/pathway","slug":"variable-v-is-not-defined","errorCode":null,"errorMessage":"variable {v} is not defined","messagePattern":"variable (.+?) is not defined","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/yaml_loader.py","lineNumber":161,"sourceCode":"        if self.parent is not None:\n            return self.parent.resolve_variable(v)\n\n        if all(c.upper() or c == \"_\" for c in v.name):\n            s = os.environ.get(v.name)\n            if s is not None:\n                # using yaml.Loader instead of PathwayYamlLoader to prevent recursive\n                # parsing of environment variables\n                parsed_value = yaml.load(s, yaml.Loader)\n                if (\n                    isinstance(parsed_value, int)\n                    or isinstance(parsed_value, float)\n                    or isinstance(parsed_value, bool)\n                ):\n                    return parsed_value\n                else:\n                    return s\n\n        raise KeyError(f\"variable {v} is not defined\")\n\n    def resolve_variable(self, v: Variable) -> object:\n        res = self._resolve_variable(v)\n        self.context[v] = res\n        self.done[id(res)] = res\n        return res\n\n    def __enter__(self) -> Self:\n        return self\n\n    def __exit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_value: BaseException | None,\n        traceback: TracebackType | None,\n        /,\n    ) -> None:\n        if exc_value is not None:","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/yaml_loader.py#L143-L179","documentation":"KeyError raised by the YAML variable resolver when a $variable used in a Pathway YAML file is found neither in the provided variables mapping (nor its parent resolvers) nor in the environment. For all-uppercase names (optionally with underscores) the resolver falls back to os.environ before failing.","triggerScenarios":"YAML contains $password, $api_key or ${PORT} but pw.load_yaml_from_file(..., variables={...}) does not define it and (for all-caps names) no matching env var exists. Mixed/lowercase names never consult the environment, so they must be passed in the variables dict.","commonSituations":"Deploying a YAML pipeline without its secrets env vars; renaming a variable in YAML but not in the variables dict; assuming lowercase variables are read from the environment (only ALL_CAPS names are); CI missing env configuration.","solutions":["Pass the missing variable: pw.load_yaml_from_file('pipeline.yaml', variables={'password': ...})","For env-sourced variables, use an ALL_UPPERCASE name (letters, digits and _ only) and export it in the environment","Audit the YAML for all $ occurrences and ensure each is defined"],"exampleFix":"# pipeline.yaml uses $API_KEY\n# before\npw.load_yaml_from_file('pipeline.yaml', variables={})\n\n# after\npw.load_yaml_from_file('pipeline.yaml', variables={'API_KEY': os.environ['API_KEY']})","handlingStrategy":"try-catch","validationCode":"import re\n\ndef yaml_variables_defined(text: str, variables: dict) -> list[str]:\n    used = set(re.findall(r'\\$(\\w+)', text))\n    provided = set(variables)\n    return sorted(used - provided)","typeGuard":null,"tryCatchPattern":"try:\n    pw.load_yaml_from_file('pipeline.yaml', variables=variables)\nexcept KeyError as e:\n    msg = str(e)\n    if 'variable' in msg and 'is not defined' in msg:\n        missing = msg.split('\"')[1] if '\"' in msg else msg\n        raise RuntimeError(f'Missing YAML variable: {missing}; pass it via variables= or env') from e\n    raise","preventionTips":["Pre-scan YAML for $variables and diff against the variables dict","Use ALL_CAPS names backed by environment variables in deployments","Fail fast at startup with a clear message instead of relying on the raw KeyError"],"tags":["pathway","yaml","variables","configuration"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}