{"record":{"id":"cab14b668555dd20","repo":"OpenBB-finance/OpenBB","slug":"hierarchy-base-hierarchy-id-or-table-id-not-fo","errorCode":null,"errorMessage":"Hierarchy '{base_hierarchy_id or table_id}' not found in cache","messagePattern":"Hierarchy '(.+?)' not found in cache","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/metadata.py","lineNumber":1492,"sourceCode":"                )\n            # Check if this is a split table (format: \"base_id:top_level_code_id\")\n            if \":\" in table_id:\n                base_hierarchy_id, top_level_code_filter = table_id.split(\":\", 1)\n            else:\n                base_hierarchy_id = table_id\n        else:\n            selected_table = available_hierarchies[0]\n            table_id = selected_table.get(\"id\", \"\")\n            if table_id and \":\" in table_id:\n                base_hierarchy_id, top_level_code_filter = table_id.split(\":\", 1)\n            else:\n                base_hierarchy_id = table_id\n\n        # Handle hierarchy-based presentations\n        # Use base_hierarchy_id to look up the actual hierarchy object\n        hierarchy = self.hierarchies.get(base_hierarchy_id or table_id)\n        if not hierarchy:\n            raise ValueError(\n                f\"Hierarchy '{base_hierarchy_id or table_id}' not found in cache\"\n            )\n\n        if not table_id:\n            raise ValueError(\"table_id cannot be None\")\n\n        codelist_id = self._hierarchy_to_codelist_map.get(base_hierarchy_id or table_id)\n\n        dataflow_obj = self.dataflows.get(dataflow_id, {})\n        agency_id = dataflow_obj.get(\"agencyID\", \"IMF\")\n        agency_clean = agency_id.replace(\".\", \"_\")\n\n        structure_ref = dataflow_obj.get(\"structureRef\", {})\n        dsd_id = structure_ref.get(\"id\")\n        dsd_obj = self.datastructures.get(dsd_id, {}) if dsd_id else {}\n        dimensions = dsd_obj.get(\"dimensions\", []) if isinstance(dsd_obj, dict) else []\n\n        indicator_dimension_order: dict[str, int] = {}","sourceCodeStart":1474,"sourceCodeEnd":1510,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/metadata.py#L1474-L1510","documentation":"Internal consistency error: the selected table id resolved, but the underlying hierarchy object is missing from self.hierarchies (keyed by base_hierarchy_id, i.e. the part before ':'). It means the available-hierarchies list and the raw hierarchy cache are out of sync — typically a partially loaded or stale hierarchy.json.","triggerScenarios":"available_hierarchies derived from one cache (e.g. DSD/codelist mapping) referencing a hierarchy id that was pruned or never loaded into self.hierarchies; concurrent cache population racing the read.","commonSituations":"Interrupted first-load of hierarchy metadata, mixed-version cached JSON files, new hierarchies advertised by the catalog before their definitions are downloadable.","solutions":["Clear and re-download the IMF hierarchy metadata caches so self.hierarchies and the availability list are rebuilt together.","If it persists, the upstream mapping is inconsistent — catch the ValueError and fall back to the flat indicator list.","Report the specific hierarchy id to the provider maintainers if reproducible after a cache refresh."],"exampleFix":"# before\ntable = meta.get_dataflow_hierarchy_table(df_id, table_id)\n\n# after\ntry:\n    table = meta.get_dataflow_hierarchy_table(df_id, table_id)\nexcept ValueError as e:\n    if 'not found in cache' in str(e):\n        meta.hierarchies.clear()  # force re-fetch on next init\n        meta = IMFSDMXMetadata(...)  # reload\n        table = meta.get_dataflow_hierarchy_table(df_id, table_id)\n    else:\n        raise","handlingStrategy":"fallback","validationCode":"base = (table_id or '').split(':')[0]\nhierarchy_cached = base in meta.hierarchies\nif not hierarchy_cached:\n    meta = rebuild_metadata()  # refresh caches before calling","typeGuard":null,"tryCatchPattern":"try:\n    meta.get_dataflow_hierarchy_table(df_id, table_id)\nexcept ValueError as e:\n    if 'not found in cache' in str(e):\n        # internal cache desync: rebuild once, then give up with flat fallback\n        table = {'indicators': meta.get_indicators_in(df_id)}\n    else:\n        raise","preventionTips":["Invalidate all IMF metadata caches together (dataflows, datastructures, hierarchies).","Treat cache-desync errors as non-retryable until caches are refreshed."],"tags":["imf","sdmx","hierarchy","cache","consistency"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}