{"record":{"id":"86182f6f02dcdca8","repo":"OpenBB-finance/OpenBB","slug":"agency-id-not-found-for-dataflow-dataflow-id","errorCode":null,"errorMessage":"Agency ID not found for dataflow '{dataflow_id}'.","messagePattern":"Agency ID not found for dataflow '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/metadata.py","lineNumber":712,"sourceCode":"        if dataflow_id not in self.dataflows:\n            raise ValueError(f\"Dataflow '{dataflow_id}' not found.\")\n\n        kwargs_sorted = sorted(kwargs.items())\n        kwargs_tuple = tuple(kwargs_sorted)\n\n        cache_key = (\n            f\"{dataflow_id}:{key}:{component_id}:{mode}:{references}:{kwargs_tuple}\"\n        )\n\n        with self._constraints_lock:\n            if cached_constraints := self._constraints_cache.get(cache_key):\n                return cached_constraints\n\n        df = self.dataflows[dataflow_id]\n        agency_id = df.get(\"agencyID\")\n\n        if not agency_id:\n            raise ValueError(f\"Agency ID not found for dataflow '{dataflow_id}'.\")\n\n        # Note: URL length is now primarily managed by table_builder.py which limits\n        # constraint keys to depth 0-1 codes when there are many indicators.\n        # This fallback is kept as a safety net for edge cases.\n        processed_key = key\n\n        base_url = (\n            f\"https://api.imf.org/external/sdmx/3.0/availability/dataflow/\"\n            f\"{agency_id}/{dataflow_id}/%2B/{processed_key}/{component_id or 'all'}\"\n        )\n        query_params = {\n            \"mode\": mode,\n            \"references\": references,\n        }\n        c_params = {f\"c[{k}]\": v for k, v in kwargs.items() if v}\n        query_params.update(c_params)\n\n        query_params = {k: v for k, v in query_params.items() if v is not None}","sourceCodeStart":694,"sourceCodeEnd":730,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/metadata.py#L694-L730","documentation":"Raised in the constraints fetcher after the dataflow ID was found in the catalog but its entry has no 'agencyID' field, which is required to build the SDMX availability URL (.../availability/dataflow/{agency_id}/{dataflow_id}/...). This indicates malformed or incomplete catalog metadata rather than bad user input — the dataflow record exists but is missing a mandatory attribute.","triggerScenarios":"A catalog entry loaded from a truncated/failed metadata fetch where agencyID was never populated; custom or mock dataflows injected without agencyID; a schema change in the IMF SDMX registry that renamed the attribute.","commonSituations":"Intermittent metadata initialization leaving partial records; pinning the provider to an old version against a changed upstream registry; test fixtures with hand-built dataflow dicts.","solutions":["Rebuild the metadata object so the catalog reloads fully from the IMF registry.","Update the provider package (pip install -U openbb-imf) in case the attribute name changed upstream.","If using custom/mocked catalogs, ensure every dataflow entry includes agencyID (e.g. 'IMF')."],"exampleFix":"# before (malformed catalog entry)\nmeta.dataflows['IMTS'] = {'id': 'IMTS', 'name': 'Trade'}  # no agencyID\nmeta.fetch_dataflow_constraints('IMTS')\n\n# after\nmeta.dataflows['IMTS'] = {'id': 'IMTS', 'name': 'Trade', 'agencyID': 'IMF', 'structureRef': {'id': 'IMTS_DSD'}}\nmeta.fetch_dataflow_constraints('IMTS')","handlingStrategy":"validation","validationCode":"entry = meta.dataflows.get(df_id)\nif not entry or not entry.get('agencyID'):\n    raise ValueError(f'Dataflow {df_id!r} metadata incomplete; rebuild the catalog.')\nconstraints = meta.fetch_dataflow_constraints(df_id, **kwargs)","typeGuard":"def is_complete_dataflow_entry(entry: dict | None) -> bool:\n    return bool(entry) and isinstance(entry.get('agencyID'), str) and bool(entry['agencyID'])","tryCatchPattern":"try:\n    c = meta.fetch_dataflow_constraints(df_id, **kwargs)\nexcept ValueError as e:\n    if 'Agency ID not found' in str(e):\n        meta = rebuild_metadata()  # re-run the catalog load\n        c = meta.fetch_dataflow_constraints(df_id, **kwargs)\n    else:\n        raise","preventionTips":["Validate catalog entries have agencyID before use, especially in tests with mocked metadata.","Rebuild metadata objects after failed loads instead of reusing them.","Keep openbb-imf current with the IMF SDMX registry schema."],"tags":["metadata","imf","data-corruption","sdmx","constraints"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}