{"record":{"id":"32504596637f069a","repo":"OpenBB-finance/OpenBB","slug":"unknown-attribute-attr-for-commodity-valid","errorCode":null,"errorMessage":"Unknown attribute: '{attr}' for {commodity}. Valid attributes: {valid_attrs}","messagePattern":"Unknown attribute: '(.+?)' 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":298,"sourceCode":"\n    commodity_code = COMMODITIES[key]\n    valid_attrs = _get_commodity_attributes(commodity_code)\n    # Resolve attribute - None means ALL, can be single, list, or comma-separated\n    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:","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L280-L316","documentation":"ValueError while validating each requested attribute: the normalized attribute key is not present in the global static ATTRIBUTES dictionary at all. This is a global-vocabulary miss (the attribute does not exist for any commodity), distinct from the commodity-specific availability check that follows.","triggerScenarios":"Passing attribute='product' when the vocabulary uses 'production'; passing units or column aliases instead of the canonical attribute names; typos.","commonSituations":"Users copying column names from the PSD website UI that differ from the API attribute keys; assuming an attribute exists because it appears in another USDA dataset.","solutions":["Use a name from the global ATTRIBUTES keys (e.g. 'production', 'imports', 'exports', 'ending_stocks').","List the valid attributes for the commodity first via _get_commodity_attributes(commodity_code) or the error's valid_attrs.","Normalize free-text input to snake_case before passing."],"exampleFix":"# before\nfetch(attribute=\"end stocks\")\n\n# after\nfetch(attribute=\"ending_stocks\")","handlingStrategy":"validation","validationCode":"from openbb_government_us.utils.psd_data_downloader import ATTRIBUTES\n\ndef normalize_attribute(a: str) -> str | None:\n    key = a.lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n    return key if key in ATTRIBUTES else None","typeGuard":"def is_valid_psd_attribute(a: str) -> bool is not None and isinstance(a, str) and a.lower().replace(\" \", \"_\").replace(\"-\", \"_\") in ATTRIBUTES","tryCatchPattern":null,"preventionTips":["Map UI labels to canonical ATTRIBUTES keys explicitly.","Validate every element of comma-separated attribute lists before calling."],"tags":["validation","psd","attribute","enum"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}