{"record":{"id":"6744a90543be413a","repo":"OpenBB-finance/OpenBB","slug":"data-structure-not-found-for-dataflow-dataflow","errorCode":null,"errorMessage":"Data structure not found for dataflow '{dataflow}'.","messagePattern":"Data structure not found for dataflow '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/query_builder.py","lineNumber":35,"sourceCode":"\n    def build_url(\n        self,\n        dataflow: str,\n        start_date: str | None = None,\n        end_date: str | None = None,\n        limit: int | None = None,\n        **kwargs,\n    ) -> str:\n        \"\"\"Build the IMF SDMX REST API URL for data retrieval.\"\"\"\n        if dataflow not in self.metadata.dataflows:\n            raise ValueError(f\"Dataflow '{dataflow}' not found.\")\n\n        df = self.metadata.dataflows[dataflow]\n        agency_id = df.get(\"agencyID\")\n        dsd_id = df.get(\"structureRef\", {}).get(\"id\")\n\n        if not dsd_id or dsd_id not in self.metadata.datastructures:\n            raise ValueError(f\"Data structure not found for dataflow '{dataflow}'.\")\n\n        dsd = self.metadata.datastructures[dsd_id]\n        all_dimensions = dsd.get(\"dimensions\", [])\n        dimension_ids = {d[\"id\"] for d in all_dimensions if d.get(\"id\")}\n        # Create a map for case-insensitive matching of dimension IDs\n        dimension_id_map = {d_id.lower(): d_id for d_id in dimension_ids}\n\n        final_kwargs: dict = {}\n\n        for key, value in kwargs.items():\n            # Try to match the key (case-insensitive) to a known dimension ID\n            matched_dim_id = dimension_id_map.get(key.lower())\n            if matched_dim_id:\n                final_kwargs[matched_dim_id] = value\n            else:\n                # If not a dimension, keep the original key\n                final_kwargs[key] = value\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/query_builder.py#L17-L53","documentation":"build_url raises ValueError when the dataflow exists in metadata but its structureRef.id is missing or that DSD is not in metadata.datastructures. Without the Data Structure Definition the builder cannot map kwargs to dimension positions in the SDMX key, so it aborts.","triggerScenarios":"Metadata loaded the dataflow list but not (all) datastructures: partial fetch, truncated cache, or IMF publishing a dataflow whose DSD is referenced but not exposed.","commonSituations":"Interrupted first-run metadata download writing a partial cache, cache format changes between provider versions, or brand-new dataflows whose DSD has not propagated.","solutions":["Delete the cached IMF metadata so dataflows and datastructures are fetched together, then retry.","Upgrade openbb-imf; structure parsing for new SDMX shapes is fixed over time.","Verify the DSD exists by querying the IMF SDMX API for the dataflow's structure.","If persisting, fall back to a different dataflow covering the same series."],"exampleFix":"# shell: force metadata refresh (location depends on install)\nrm -rf ~/.cache/openbb/imf_metadata  # then retry the same call","handlingStrategy":"fallback","validationCode":"def dataflow_has_dsd(qb, dataflow: str) -> bool:\n    df = qb.metadata.dataflows.get(dataflow, {})\n    dsd_id = df.get('structureRef', {}).get('id')\n    return bool(dsd_id) and dsd_id in qb.metadata.datastructures","typeGuard":null,"tryCatchPattern":"try:\n    url = qb.build_url(dataflow, **kwargs)\nexcept ValueError as e:\n    if 'Data structure not found' in str(e):\n        refresh_imf_metadata_cache()\n        url = qb.build_url(dataflow, **kwargs)\n    else:\n        raise","preventionTips":["Treat dataflows and datastructures as one atomic metadata unit when caching.","Refetch metadata on provider upgrade instead of reusing old caches.","Pre-check structureRef.id presence before build_url in long-running jobs."],"tags":["metadata","imf","sdmx","cache","partial-state"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}