OpenBB-finance/OpenBB · error · ValueError
Attribute '{attr}' is not available for {commodity}. Valid a
Error message
Attribute '{attr}' is not available for {commodity}. Valid attributes: {valid_attrs} What it means
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.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py:302
if attribute is None:
attr_ids = [ATTRIBUTES[a] for a in valid_attrs]
else:
# Normalize to list
if isinstance(attribute, str):
attr_list = [a.strip() for a in attribute.split(",") if a.strip()]
else:
attr_list = list(attribute)
# Validate each attribute
attr_ids = []
for attr in attr_list:
attr_key = attr.lower().replace(" ", "_").replace("-", "_")
if attr_key not in ATTRIBUTES:
raise ValueError(
f"Unknown attribute: '{attr}' for {commodity}. Valid attributes: {valid_attrs}"
)
if attr_key not in valid_attrs:
raise ValueError(
f"Attribute '{attr}' is not available for {commodity}. Valid attributes: {valid_attrs}"
)
attr_ids.append(ATTRIBUTES[attr_key])
# Resolve country/region - None means ALL
# Accepts: lower_snake_case ("united_states"), codes ("US", "R05"), list, comma-separated, or None for all
selected_region_codes: list[str] = [] # Track selected regions
selected_country_codes: list[str] = [] # Track selected countries
valid_countries_map = _get_commodity_countries(commodity_code)
valid_country_codes = set(valid_countries_map.values())
code_to_key = {}
for key, code in COUNTRIES.items():
if code not in code_to_key:
code_to_key[code] = key
def get_valid_country_keys() -> list[str]:
"""Get sorted list of valid country keys from our COUNTRIES dict."""View on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before fetch(commodity="cotton", attribute="area_harvested") # not offered # after fetch(commodity="cotton", attribute=None) # all available attributes
Defensive patterns
Strategy: validation
Validate before calling
from openbb_government_us.utils.psd_data_downloader import _get_commodity_attributes, COMMODITIES
def attributes_for(commodity: str) -> list[str]:
return _get_commodity_attributes(COMMODITIES[commodity.lower().replace(" ", "_").replace("-", "_")])
def is_available(commodity: str, attribute: str) -> bool:
key = attribute.lower().replace(" ", "_").replace("-", "_")
return key in attributes_for(commodity) Type guard
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) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Generic dashboards applying the same attribute list to every commodity; users assuming all attributes apply everywhere.
Related errors
- Unknown commodity: {commodity} -> Valid choices: {valid_choi
- Unknown attribute: '{attr}' for {commodity}. Valid attribute
- Country '{c}' is not available for {commodity}. Valid countr
- Report ID {report_id} not found. Use list_reports() to see a
- Invalid report ID -> {report_id} was not found.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/617b0b1311df51c7.
Report an issue: GitHub.