{"record":{"id":"4db81816d72e8a04","repo":"OpenBB-finance/OpenBB","slug":"invalid-data-format-expected-a-list-of-imfmaritim","errorCode":null,"errorMessage":"Invalid data format. Expected a list of ImfMaritimeChokePointInfoData.","messagePattern":"Invalid data format\\. Expected a list of ImfMaritimeChokePointInfoData\\.","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py","lineNumber":30,"sourceCode":"    from openbb_core.app.model.abstract.error import OpenBBError\n    from pandas import DataFrame\n\n    try:\n        from openbb_charting.core.openbb_figure import OpenBBFigure\n        from plotly import graph_objects as go\n        from plotly.subplots import make_subplots\n    except Exception as e:\n        raise OpenBBError(\n            \"Could not import Charting modules. Install with `pip install openbb-charting`.\"\n            + f\" -> {e}\"\n        ) from e\n\n    if (\n        data is not None\n        and not isinstance(data, list)\n        or not all(isinstance(item, ImfMaritimeChokePointInfoData) for item in data)\n    ):\n        raise OpenBBError(\n            \"Invalid data format. Expected a list of ImfMaritimeChokePointInfoData.\"\n        )\n    if len(data) == 0:\n        raise OpenBBError(\"No data to plot.\")\n\n    df = DataFrame([item.model_dump() for item in data])\n    if theme == \"dark\":\n        geo_bgcolor = \"rgba(0,0,0,0)\"\n        landcolor = \"#3a5d3a\"\n        countrycolor = \"#cccccc\"\n        oceancolor = \"#223355\"\n        coastlinecolor = \"#cccccc\"\n        lakecolor = \"#0d47a1\"\n        rivercolor = \"#0d47a1\"\n        table_header_fill = \"#222e3c\"\n        table_header_font = \"#fff\"\n        table_cell_fill = [\"#232323\", \"#181818\"] * (len(df) // 2 + 1)\n        font_color = \"#fff\"","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/views/maritime_chokepoint_info.py#L12-L48","documentation":"Type guard in the maritime chokepoint chart view: the data argument must be a list whose items are all ImfMaritimeChokePointInfoData. Because of Python operator precedence, the condition is effectively (data is not None and not isinstance(data, list)) or (not all(isinstance(item, ...) for item in data)) - so a non-list iterable or any non-conforming item triggers it. Note it does not guard against data=None, which instead fails later at len().","triggerScenarios":"Passing a DataFrame, a generator, a list of dicts, or a mixed list (e.g. result rows appended with raw dicts) into plot_maritime_chokepoint_info instead of validated model instances; also passing None (falls through the guard, then crashes on len(data)).","commonSituations":"Custom pipelines that re-serialize fetcher output to dicts before plotting; combining results from multiple providers where item types differ; test code passing mocks that aren't ImfMaritimeChokePointInfoData instances.","solutions":["Pass the fetcher/endpoint's return value (list of ImfMaritimeChokePointInfoData) directly to the view without re-serializing.","If you have dicts, convert first: [ImfMaritimeChokePointInfoData.model_validate(d) for d in rows].","Guard against None before calling (the built-in check doesn't reject it).","Avoid mixing items from different provider models in one call."],"exampleFix":"# before\nplot_maritime_chokepoint_info([{'date': '...', 'chokepoint': 'Suez', ...}])\n# after\nfrom openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData\ndata = [ImfMaritimeChokePointInfoData.model_validate(d) for d in rows]\nplot_maritime_chokepoint_info(data)","handlingStrategy":"type-guard","validationCode":"from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData\n\ndef is_chokepoint_data_list(data) -> bool:\n    return isinstance(data, list) and len(data) > 0 and all(\n        isinstance(i, ImfMaritimeChokePointInfoData) for i in data\n    )\n\nassert is_chokepoint_data_list(data), 'pass model instances, not dicts'","typeGuard":"from openbb_imf.models.maritime_chokepoint_info import ImfMaritimeChokePointInfoData\n\ndef is_chokepoint_data_list(data: object) -> bool:\n    return isinstance(data, list) and len(data) > 0 and all(\n        isinstance(i, ImfMaritimeChokePointInfoData) for i in data\n    )","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\ntry:\n    plot_maritime_chokepoint_info(data)\nexcept OpenBBError as e:\n    if 'Invalid data format' in str(e):\n        data = [ImfMaritimeChokePointInfoData.model_validate(d) for d in data]\n        plot_maritime_chokepoint_info(data)\n    else:\n        raise","preventionTips":["Never re-serialize fetcher results to dicts before charting","Keep None out - the built-in guard doesn't reject it","Validate list homogeneity before calling chart views"],"tags":["imf","type-validation","charting","openbberror"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}