{"record":{"id":"b0a9043c258967a1","repo":"OpenBB-finance/OpenBB","slug":"expected-values-as-valid-portids-got-none-instead","errorCode":null,"errorMessage":"Expected values as valid portIDs, got None instead.","messagePattern":"Expected values as valid portIDs, got None instead\\.","errorType":"validation","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/models/port_volume.py","lineNumber":423,"sourceCode":"        **kwargs: Any,\n    ) -> list:\n        \"\"\"Extract data from the IMF Port Volume API.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        import asyncio  # noqa\n        from openbb_imf.utils.port_watch_helpers import get_daily_port_activity_data\n\n        port_codes = (\n            get_port_ids_by_country(query.country)\n            if query.country\n            else (\n                query.port_code.split(\",\")\n                if isinstance(query.port_code, str)\n                else query.port_code\n            )\n        )\n\n        if not port_codes:\n            raise OpenBBError(\"Expected values as valid portIDs, got None instead.\")\n\n        output: list = []\n\n        async def fetch_port_data(port_code: str):\n            \"\"\"Fetch data for a single port.\"\"\"\n            try:\n                data = await get_daily_port_activity_data(\n                    port_code, query.start_date, query.end_date\n                )\n                if data:\n                    output.extend(data)\n            except Exception as e:\n                raise OpenBBError(\n                    f\"Failed to fetch data for port {port_code}: {e} -> {e.args}\"\n                ) from e\n\n        tasks = [fetch_port_data(port_code=port_code) for port_code in port_codes]\n","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/models/port_volume.py#L405-L441","documentation":"Raised in ImfPortVolumeFetcher.aawindow (the async data step) when the resolved port_codes sequence is falsy — either query.port_code is None/empty, or get_port_ids_by_country(query.country) returned an empty list. It signals that the country->ports lookup produced nothing, so there is no port to query. The message ('got None instead') slightly misleads: an empty list from an unknown country triggers it too.","triggerScenarios":"Passing country='atlantis' (or a valid country with no PortWatch ports) so get_port_ids_by_country returns []; or constructing ImfPortVolumeQueryParams in a way that leaves port_code falsy after validation.","commonSituations":"Assuming every country has ports in the PortWatch dataset; passing country names in the wrong format (display name vs snake_case); chained workflows where the country resolution step silently yields [].","solutions":["Verify the country has PortWatch ports and pass explicit port_codes instead: use the provider's port map / IMF PortWatch explorer to find valid IDs.","If country-based selection matters, check the return of get_port_ids_by_country(country) before calling and surface a clear error when empty.","Fall back to the default port (port1114) when no ports resolve."],"exampleFix":"# before\nres = await obb.economy.port_volume(provider='imf', country='liechtenstein')  # no ports -> empty lookup\n\n# after\nfrom openbb_imf.models.port_volume import get_port_ids_by_country\nports = get_port_ids_by_country('liechtenstein')\nif not ports:\n    raise ValueError(f'No IMF PortWatch ports for this country; pass port_code explicitly.')\nres = await obb.economy.port_volume(provider='imf', port_code=','.join(ports))","handlingStrategy":"validation","validationCode":"from openbb_imf.models.port_volume import get_port_ids_by_country\nports = get_port_ids_by_country(country) if country else None\nif not ports:\n    ports = ['port1114']  # or raise your own informative error\nres = await obb.economy.port_volume(provider='imf', port_code=','.join(ports))","typeGuard":"def has_resolvable_ports(country: str | None, port_code: str | None) -> bool:\n    if port_code and port_code.strip():\n        return True\n    if country:\n        from openbb_imf.models.port_volume import get_port_ids_by_country\n        return bool(get_port_ids_by_country(country))\n    return False","tryCatchPattern":"try:\n    res = await obb.economy.port_volume(provider='imf', country=country)\nexcept OpenBBError as e:\n    if 'valid portIDs' in str(e):\n        res = await obb.economy.port_volume(provider='imf', port_code='port1114')","preventionTips":["Check get_port_ids_by_country(country) is non-empty before relying on country-only queries.","Prefer explicit port_codes in automated pipelines.","Note: message says 'None' but an empty list triggers it too."],"tags":["validation","imf","ports","country-lookup","fetcher"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}