{"record":{"id":"11760db7b9bf56c6","repo":"OpenBB-finance/OpenBB","slug":"year-must-be-1935-or-later","errorCode":null,"errorMessage":"Year must be 1935 or later.","messagePattern":"Year must be 1935 or later\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py","lineNumber":34,"sourceCode":"\n# pylint: disable=R0903\nclass BillsState(metaclass=SingletonMeta):\n    \"\"\"Singleton class to manage application cache.\"\"\"\n\n    def __init__(self):\n        \"\"\"Initialize the BillsState.\"\"\"\n        if not hasattr(self, \"bills\"):\n            self.bills = {}\n\n\ndef year_to_congress(year: int) -> int:\n    \"\"\"\n    Map a year (1935-present) to the corresponding U.S. Congress number.\n\n    Raises ValueError if the year is before 1935.\n    \"\"\"\n    if year < 1935:\n        raise ValueError(\"Year must be 1935 or later.\")\n    # 74th Congress started in 1935\n    congress_number = 74 + ((year - 1935) // 2)\n    return congress_number\n\n\ndef check_api_key() -> str:\n    \"\"\"Check if the Congress.gov API key is set in user settings.\n\n    Raises UnauthorizedError if the API key is not set.\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    from openbb_core.app.service.user_service import UserSettings\n    from pydantic import SecretStr\n\n    credentials = UserSettings().credentials\n    api_key = getattr(\n        credentials, \"congress_gov_api_key\", SecretStr(\"\")\n    ).get_secret_value()","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"Historical research on pre-New Deal legislation; typos in ISO dates (e.g. 1890 vs 1980); feeding user-supplied year input without bounds checking.","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"],"exampleFix":"# before\ncongress = year_to_congress(int(user_year))\n\n# after\nif int(user_year) < 1935:\n    raise ValueError(f\"Year {user_year} predates supported range (1935+).\")\ncongress = year_to_congress(int(user_year))","handlingStrategy":"validation","validationCode":"def assert_supported_year(year: int) -> int:\n    if year < 1935:\n        raise ValueError(f'Year {year} not supported; must be >= 1935.')\n    return year","typeGuard":"def is_supported_year(year: int) -> bool:\n    return isinstance(year, int) and year >= 1935","tryCatchPattern":"try:\n    congress = year_to_congress(year)\nexcept ValueError:\n    congress = None  # or reject the input at the UI layer","preventionTips":["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"],"tags":["congress-gov","validation","date-range"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}