{"record":{"id":"45bcb87d9a95143a","repo":"OpenBB-finance/OpenBB","slug":"country-and-counterpart-parameters-cannot-be-empty","errorCode":null,"errorMessage":"Country and counterpart parameters cannot be empty.","messagePattern":"Country and counterpart parameters cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py","lineNumber":165,"sourceCode":"        The frequency of the data, by default \"A\" (annual).\n    start_date : str | None\n        The start date of the data, by default None.\n    end_date : str | None\n        The end date of the data, by default None.\n    **kwargs : dict\n        Additional query parameters to pass to the API.\n\n    Returns\n    -------\n    dict\n        A dictionary with keys: 'data' containing the fetched data,\n        and 'metadata' containing the related metadata.\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    from openbb_imf.utils.query_builder import ImfQueryBuilder\n\n    if not country or not counterpart:\n        raise ValueError(\"Country and counterpart parameters cannot be empty.\")\n\n    freq = freq[0].upper()\n\n    if freq and freq not in [\"A\", \"Q\", \"M\"]:\n        raise ValueError(\"Frequency must be one of 'A', 'Q', or 'M'.\")\n\n    query_builder = ImfQueryBuilder()\n    dataflow_id = \"IMTS\"\n    params = query_builder.metadata.get_dataflow_parameters(dataflow_id)\n    country_values = {item[\"value\"] for item in params.get(\"COUNTRY\", [])}\n    counterpart_values = {\n        item[\"value\"]\n        for item in params.get(\"COUNTERPART_COUNTRY\", params.get(\"COUNTRY\", []))\n    }\n\n    def _validate_selection(selection, valid_values, name):\n        \"\"\"Validate country or counterpart selection.\"\"\"\n        if not valid_values:","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py#L147-L183","documentation":"Raised at the entry of imts_query (IMF Direction of Trade / International Merchandise Trade Statistics builder) when either the country or the counterpart argument is falsy. Both sides of a trade query are mandatory — the function builds an SDMX key that needs a reporter and a partner — so an empty side aborts before any validation or request.","triggerScenarios":"imts_query(country=None, counterpart='USA', ...) or counterpart='' from a UI where the user selected only one side of the trade pair; forgetting that counterpart is a required positional arg.","commonSituations":"Optional-looking parameters in wrapper code defaulting to None; multi-select forms where the partner-country field was skipped; refactoring from bilateral(country_a, country_b) signatures.","solutions":["Always pass both sides: country (reporter) and counterpart (partner).","Use '*' as counterpart to get trade with all partners when a single partner was not intended.","Validate both args non-empty before calling in pipelines built from user input."],"exampleFix":"# before\nres = imts_query(country='USA', counterpart='', indicator='TXG_FOB_USD')\n\n# after\nres = imts_query(country='USA', counterpart='*', indicator='TXG_FOB_USD')","handlingStrategy":"validation","validationCode":"if not country or not counterpart:\n    counterpart = counterpart or '*'\ncountry = country or 'USA'\nassert country and counterpart\nres = imts_query(country=country, counterpart=counterpart, indicator='TXG_FOB_USD')","typeGuard":"def is_valid_trade_pair(country, counterpart) -> bool:\n    def ok(v):\n        return bool(v) and (v == '*' or all(isinstance(x, str) and x.strip() for x in ([v] if isinstance(v, str) else v)))\n    return ok(country) and ok(counterpart)","tryCatchPattern":"try:\n    res = imts_query(country=c, counterpart=cp, indicator=ind)\nexcept ValueError as e:\n    if 'cannot be empty' in str(e):\n        cp = '*'\n        res = imts_query(country=c, counterpart=cp, indicator=ind)\n    else:\n        raise","preventionTips":["Treat counterpart as required; default to '*' for 'all partners'.","Validate both sides non-empty in wrapper functions.","Unit-test wrappers with one-sided inputs."],"tags":["validation","imf","dot","parameters","trade"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}