OpenBB-finance/OpenBB · warning · ValueError

table_id cannot be None

Error message

table_id cannot be None

What it means

Defensive guard in get_dataflow_hierarchy_table: after hierarchy resolution, table_id is still falsy. In practice this only happens when no table_id was passed and the first available hierarchy entry has an empty/missing 'id' — the earlier 'if not table_id' branches never assigned a real value. It marks corrupt hierarchy entries rather than a user mistake.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/utils/metadata.py:1497

                base_hierarchy_id = table_id
        else:
            selected_table = available_hierarchies[0]
            table_id = selected_table.get("id", "")
            if table_id and ":" in table_id:
                base_hierarchy_id, top_level_code_filter = table_id.split(":", 1)
            else:
                base_hierarchy_id = table_id

        # Handle hierarchy-based presentations
        # Use base_hierarchy_id to look up the actual hierarchy object
        hierarchy = self.hierarchies.get(base_hierarchy_id or table_id)
        if not hierarchy:
            raise ValueError(
                f"Hierarchy '{base_hierarchy_id or table_id}' not found in cache"
            )

        if not table_id:
            raise ValueError("table_id cannot be None")

        codelist_id = self._hierarchy_to_codelist_map.get(base_hierarchy_id or table_id)

        dataflow_obj = self.dataflows.get(dataflow_id, {})
        agency_id = dataflow_obj.get("agencyID", "IMF")
        agency_clean = agency_id.replace(".", "_")

        structure_ref = dataflow_obj.get("structureRef", {})
        dsd_id = structure_ref.get("id")
        dsd_obj = self.datastructures.get(dsd_id, {}) if dsd_id else {}
        dimensions = dsd_obj.get("dimensions", []) if isinstance(dsd_obj, dict) else []

        indicator_dimension_order: dict[str, int] = {}
        indicator_id_candidates = [
            "INDICATOR",
            "PRODUCTION_INDEX",
            "COICOP_1999",
            "ACTIVITY",

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Pass an explicit, known-good table_id (from get_dataflow_hierarchies) instead of relying on the first entry.
  2. Inspect available_hierarchies[0] for a missing 'id' and refresh the metadata caches.
  3. Filter entries without ids when building your own table picker.

Example fix

# before
table = meta.get_dataflow_hierarchy_table(df_id, None)

# after
ids = [h['id'] for h in meta.get_dataflow_hierarchies(df_id) if h.get('id')]
table = meta.get_dataflow_hierarchy_table(df_id, ids[0] if ids else None)
Defensive patterns

Strategy: validation

Validate before calling

ids = [h['id'] for h in meta.get_dataflow_hierarchies(df_id) if h.get('id')]
safe_table_id = ids[0] if ids else None
if safe_table_id is None:
    raise ValueError('No well-formed hierarchy entries for this dataflow')

Try / catch

try:
    meta.get_dataflow_hierarchy_table(df_id, None)
except ValueError as e:
    if 'table_id cannot be None' in str(e):
        pass  # corrupt first entry: handled by pre-filtering ids
    else:
        raise

Prevention

When it happens

Trigger: table_id=None plus available_hierarchies[0] lacking an 'id' key or having id=''; a malformed hierarchy.json entry with no id.

Common situations: Hand-edited or truncated hierarchy cache files; upstream JSON schema change dropping the id field.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/096286b888088bd5. Report an issue: GitHub.