{"record":{"id":"ebef9485f890363e","repo":"OpenBB-finance/OpenBB","slug":"either-port-id-or-country-code-must-be-provided","errorCode":null,"errorMessage":"Either port_id or country_code must be provided.","messagePattern":"Either port_id or country_code must be provided\\.","errorType":"validation","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py","lineNumber":312,"sourceCode":"    \"\"\"Get the daily port activity data for a specific port ID.\n\n    Parameters\n    ----------\n    port_id : str\n        The port ID for which to fetch daily activity data.\n\n    Returns\n    -------\n    list\n        A list of dictionaries, each representing daily activity data for the specified port.\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    from datetime import datetime  # noqa\n    from openbb_core.app.model.abstract.error import OpenBBError\n    from openbb_core.provider.utils.helpers import get_async_requests_session\n\n    if port_id is None:\n        raise OpenBBError(\n            ValueError(\"Either port_id or country_code must be provided.\")\n        )\n\n    if start_date is not None and end_date is None:\n        end_date = datetime.now().strftime(\"%Y-%m-%d\")\n\n    if start_date is None and end_date is not None:\n        start_date = \"2019-01-01\"\n\n    def get_port_url(offset: int):\n        \"\"\"Construct the URL for fetching chokepoint data with offset.\"\"\"\n        nonlocal port_id, start_date, end_date\n        return (\n            (\n                DAILY_TRADE_BASE_URL\n                + f\"where=portid%20%3D%20%27{port_id.upper()}%27&\"  # type: ignore\n                + f\"outFields=*&orderByFields=date&returnZ=true&resultOffset={offset}&resultRecordCount=1000\"\n                + \"&maxRecordCountFactor=5&outSR=&f=json\"","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/port_watch_helpers.py#L294-L330","documentation":"Input guard at the top of get_daily_port_activity_data: port_id is None and the function has no country_code parameter to fall back on, so it cannot build a query URL and raises OpenBBError wrapping a ValueError. It is purely a caller-contract violation — despite the message mentioning country_code, this code path requires a concrete port id.","triggerScenarios":"Calling get_daily_port_activity_data(None) or with an unset variable; code that assumed country-level aggregation was supported by this function.","commonSituations":"Optional fields from a UI/dataclass defaulting to None and being passed through; refactors where a get_port_ids_by_country result was expected but never resolved to an actual port id.","solutions":["Resolve a concrete port id first (e.g. via get_port_ids_by_country) and pass that.","Add a None check at your call site with a clear message instead of relying on the provider's.","If you need country-wide activity, use the country-level helper, not this function."],"exampleFix":"# before\ndata = await get_daily_port_activity_data(port_id=None)\n\n# after\nif port_id is None:\n    port_id = get_port_ids_by_country(country_code)  # or another resolution step\ndata = await get_daily_port_activity_data(port_id)","handlingStrategy":"validation","validationCode":"if not port_id:  # None or empty\n    raise ValueError('port_id is required for per-port activity data')","typeGuard":"def has_port_id(port_id: object) -> bool:\n    return isinstance(port_id, (str, int)) and bool(str(port_id).strip())","tryCatchPattern":"try:\n    await get_daily_port_activity_data(port_id, start, end)\nexcept OpenBBError as e:\n    if 'port_id or country_code' in str(e):\n        raise InvalidInput('Resolve a port id before querying') from e\n    raise","preventionTips":["Resolve port ids via get_port_ids_by_country before per-port queries.","Reject None port ids at your own API boundary with a clearer message."],"tags":["imf","port-watch","validation","port-id","input"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}