{"record":{"id":"fd19dbb2f9cf552c","repo":"OpenBB-finance/OpenBB","slug":"start-and-end-dates-must-be-in-the-same-congress-s","errorCode":null,"errorMessage":"Start and end dates must be in the same Congress session.","messagePattern":"Start and end dates must be in the same Congress session\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py","lineNumber":213,"sourceCode":"        raise ValueError(\n            f\"Invalid bill type: {bill_type}. Must be one of {', '.join(BillTypes)}.\"\n        )\n\n    api_key = check_api_key()\n\n    if start_date is None and end_date is None and congress is None:\n        congress = year_to_congress(datetime.now().year)\n    elif congress is None and start_date is not None:\n        congress = year_to_congress(dateType.fromisoformat(start_date).year)\n    elif congress is None and end_date is not None and start_date is None:\n        congress = year_to_congress(dateType.fromisoformat(end_date).year)\n    elif start_date is not None and end_date is not None:\n        start_year = dateType.fromisoformat(start_date).year\n        end_year = dateType.fromisoformat(end_date).year\n        congress_start = year_to_congress(start_year)\n        congress_end = year_to_congress(end_year)\n        if congress_start != congress_end:\n            raise ValueError(\n                \"Start and end dates must be in the same Congress session.\"\n            )\n        congress = congress_start\n\n    if congress is None:\n        congress = year_to_congress(datetime.now().year)\n\n    url = (\n        f\"{base_url}bill/{congress}/{bill_type}\"\n        + (f\"?fromDateTime={start_date + 'T00:00:00Z'}\" if start_date else \"\")\n        + (f\"&toDateTime={end_date + 'T23:59:59Z'}\" if end_date else \"\")\n        + f\"?limit={limit if limit is not None else 10}\"\n        + (f\"&offset={offset}\" if offset else \"\")\n        + f\"&sort=updateDate+{sort_by}\"\n        + f\"&format=json&api_key={api_key}\"\n    )\n\n    return await amake_request(url)","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py#L195-L231","documentation":"When both start_date and end_date are supplied to get_bills_by_type, the helper derives a single congress number from each date's year and requires them to match, because the underlying URL addresses one Congress at a time (/bill/{congress}/{bill_type}). A date pair spanning a Congress boundary (odd-numbered January, e.g. 2023-01-03) cannot be served by one request and raises ValueError.","triggerScenarios":"start_date='2022-06-01', end_date='2023-06-01' (117th vs 118th Congress); any range covering two January 3rds; a full-year range like 2023-01-01..2024-12-31.","commonSituations":"Default reporting windows (last 12/18 months) that cross a Congress rollover; users assuming date ranges work like other OpenBB providers that split queries automatically.","solutions":["Split the range at the Congress boundary and issue one request per Congress (117th and 118th), then concatenate","Narrow the range so both dates fall in the same Congress","Pass congress explicitly with dates fully inside that Congress's session"],"exampleFix":"# before\nres = await get_bills_by_type(bill_type='hr', start_date='2022-06-01', end_date='2023-06-01')\n\n# after\nres = []\nfor congress in (117, 118):\n    res += (await get_all_bills(congress=congress, bill_type='hr'))['bills']","handlingStrategy":"validation","validationCode":"from datetime import date\n\ndef spans_one_congress(start: str, end: str) -> bool:\n    sy, ey = date.fromisoformat(start).year, date.fromisoformat(end).year\n    # Congress N covers [1935 + 2*(N-74), +1]; same Congress iff same derived number\n    return (74 + (sy - 1935) // 2) == (74 + (ey - 1935) // 2)","typeGuard":null,"tryCatchPattern":"try:\n    res = await get_bills_by_type(bill_type='hr', start_date=s, end_date=e)\nexcept ValueError as ex:\n    if 'same Congress session' in str(ex):\n        res = []\n        for c in {year_to_congress(date.fromisoformat(d).year) for d in (s, e)}:\n            res += await get_all_bills(congress=c, bill_type='hr')\n    else:\n        raise","preventionTips":["Split date ranges at each January of an odd year (Congress starts Jan 3)","Pass congress explicitly when the session is known","Treat long ranges as multi-session and fan out one call per Congress"],"tags":["congress-gov","validation","date-range","session-boundary"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}