OpenBB-finance/OpenBB · error · ValueError
Year must be 1935 or later.
Error message
Year must be 1935 or later.
What it means
year_to_congress maps a calendar year to a Congress number using 1935 (74th Congress) as the epoch, so any year before 1935 has no valid mapping and raises ValueError. The function is used to default the congress parameter from dates or from today's date. Congress numbering did exist before 1935 but this provider deliberately does not model it.
Source
Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py:34
# pylint: disable=R0903
class BillsState(metaclass=SingletonMeta):
"""Singleton class to manage application cache."""
def __init__(self):
"""Initialize the BillsState."""
if not hasattr(self, "bills"):
self.bills = {}
def year_to_congress(year: int) -> int:
"""
Map a year (1935-present) to the corresponding U.S. Congress number.
Raises ValueError if the year is before 1935.
"""
if year < 1935:
raise ValueError("Year must be 1935 or later.")
# 74th Congress started in 1935
congress_number = 74 + ((year - 1935) // 2)
return congress_number
def check_api_key() -> str:
"""Check if the Congress.gov API key is set in user settings.
Raises UnauthorizedError if the API key is not set.
"""
# pylint: disable=import-outside-toplevel
from openbb_core.app.service.user_service import UserSettings
from pydantic import SecretStr
credentials = UserSettings().credentials
api_key = getattr(
credentials, "congress_gov_api_key", SecretStr("")
).get_secret_value()View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use dates/years >= 1935, or pass the congress number explicitly to bypass year derivation
- Validate user-supplied years at your application boundary: reject or clamp anything below 1935
- For pre-1935 data, use a different source (GovInfo, ProPublica Congress archives) since this provider will not serve it
Example fix
# before
congress = year_to_congress(int(user_year))
# after
if int(user_year) < 1935:
raise ValueError(f"Year {user_year} predates supported range (1935+).")
congress = year_to_congress(int(user_year)) Defensive patterns
Strategy: validation
Validate before calling
def assert_supported_year(year: int) -> int:
if year < 1935:
raise ValueError(f'Year {year} not supported; must be >= 1935.')
return year Type guard
def is_supported_year(year: int) -> bool:
return isinstance(year, int) and year >= 1935 Try / catch
try:
congress = year_to_congress(year)
except ValueError:
congress = None # or reject the input at the UI layer Prevention
- Bound-check user-supplied years at the input boundary
- Pass congress explicitly when you already know it
- Remember the epoch: 1935 = 74th Congress, +1 every 2 years
When it happens
Trigger: Passing start_date='1929-01-01' to bill helpers (congress is derived from the date's year); calling year_to_congress(1900) directly; a malformed date string whose parsed year lands below 1935.
Common situations: Historical research on pre-New Deal legislation; typos in ISO dates (e.g. 1890 vs 1980); feeding user-supplied year input without bounds checking.
Related errors
- Start and end dates must be in the same Congress session.
- Invalid amendment_type: {values.amendment_type}. Must be one
- 'limit' cannot be set to 0 without 'amendment_type'.
- 'congress' is required when 'limit' is set to 0.
- Invalid bill_type: {values.bill_type}. Must be one of: {', '
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/11760db7b9bf56c6.
Report an issue: GitHub.