{"record":{"id":"617b0b1311df51c7","repo":"OpenBB-finance/OpenBB","slug":"attribute-attr-is-not-available-for-commodity","errorCode":null,"errorMessage":"Attribute '{attr}' is not available for {commodity}. Valid attributes: {valid_attrs}","messagePattern":"Attribute '(.+?)' is not available for (.+?)\\. Valid attributes: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py","lineNumber":302,"sourceCode":"    if attribute is None:\n        attr_ids = [ATTRIBUTES[a] for a in valid_attrs]\n    else:\n        # Normalize to list\n        if isinstance(attribute, str):\n            attr_list = [a.strip() for a in attribute.split(\",\") if a.strip()]\n        else:\n            attr_list = list(attribute)\n\n        # Validate each attribute\n        attr_ids = []\n        for attr in attr_list:\n            attr_key = attr.lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n            if attr_key not in ATTRIBUTES:\n                raise ValueError(\n                    f\"Unknown attribute: '{attr}' for {commodity}. Valid attributes: {valid_attrs}\"\n                )\n            if attr_key not in valid_attrs:\n                raise ValueError(\n                    f\"Attribute '{attr}' is not available for {commodity}. Valid attributes: {valid_attrs}\"\n                )\n            attr_ids.append(ATTRIBUTES[attr_key])\n\n    # Resolve country/region - None means ALL\n    # Accepts: lower_snake_case (\"united_states\"), codes (\"US\", \"R05\"), list, comma-separated, or None for all\n    selected_region_codes: list[str] = []  # Track selected regions\n    selected_country_codes: list[str] = []  # Track selected countries\n    valid_countries_map = _get_commodity_countries(commodity_code)\n    valid_country_codes = set(valid_countries_map.values())\n    code_to_key = {}\n\n    for key, code in COUNTRIES.items():\n        if code not in code_to_key:\n            code_to_key[code] = key\n\n    def get_valid_country_keys() -> list[str]:\n        \"\"\"Get sorted list of valid country keys from our COUNTRIES dict.\"\"\"","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L284-L320","documentation":"The second attribute check: the key exists in the global ATTRIBUTES map but is not offered for the requested commodity (valid_attrs comes from the metadata API via _get_commodity_attributes for that commodity's code). E.g. 'yield' may be valid for grains but not for vegetable oils.","triggerScenarios":"Requesting an attribute/commodity pair the PSD database does not track, like attribute='yield' with commodity='vegatable_oil' style oils, or 'domestic_consumption' for a commodity that only reports trade.","commonSituations":"Generic dashboards applying the same attribute list to every commodity; users assuming all attributes apply everywhere.","solutions":["Pick attributes from the commodity's valid_attrs list shown in the error.","Query the commodity's attribute metadata first and intersect with your desired set.","Pass attribute=None to request all available attributes for the commodity."],"exampleFix":"# before\nfetch(commodity=\"cotton\", attribute=\"area_harvested\")  # not offered\n\n# after\nfetch(commodity=\"cotton\", attribute=None)  # all available attributes","handlingStrategy":"validation","validationCode":"from openbb_government_us.utils.psd_data_downloader import _get_commodity_attributes, COMMODITIES\n\ndef attributes_for(commodity: str) -> list[str]:\n    return _get_commodity_attributes(COMMODITIES[commodity.lower().replace(\" \", \"_\").replace(\"-\", \"_\")])\n\ndef is_available(commodity: str, attribute: str) -> bool:\n    key = attribute.lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n    return key in attributes_for(commodity)","typeGuard":"def is_valid_for_commodity(commodity: str, attribute: str) -> bool is not None and is_valid_psd_commodity(commodity) and attribute.lower().replace(\" \", \"_\").replace(\"-\", \"_\") in attributes_for(commodity)","tryCatchPattern":null,"preventionTips":["Fetch the commodity's attribute list once and cache it; drive your UI from it.","Pass attribute=None when you want everything available for the commodity."],"tags":["validation","psd","attribute","commodity"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}