OpenBB-finance/OpenBB · error · ValueError
Start and end dates must be in the same Congress session.
Error message
Start and end dates must be in the same Congress session.
What it means
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.
Source
Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py:213
raise ValueError(
f"Invalid bill type: {bill_type}. Must be one of {', '.join(BillTypes)}."
)
api_key = check_api_key()
if start_date is None and end_date is None and congress is None:
congress = year_to_congress(datetime.now().year)
elif congress is None and start_date is not None:
congress = year_to_congress(dateType.fromisoformat(start_date).year)
elif congress is None and end_date is not None and start_date is None:
congress = year_to_congress(dateType.fromisoformat(end_date).year)
elif start_date is not None and end_date is not None:
start_year = dateType.fromisoformat(start_date).year
end_year = dateType.fromisoformat(end_date).year
congress_start = year_to_congress(start_year)
congress_end = year_to_congress(end_year)
if congress_start != congress_end:
raise ValueError(
"Start and end dates must be in the same Congress session."
)
congress = congress_start
if congress is None:
congress = year_to_congress(datetime.now().year)
url = (
f"{base_url}bill/{congress}/{bill_type}"
+ (f"?fromDateTime={start_date + 'T00:00:00Z'}" if start_date else "")
+ (f"&toDateTime={end_date + 'T23:59:59Z'}" if end_date else "")
+ f"?limit={limit if limit is not None else 10}"
+ (f"&offset={offset}" if offset else "")
+ f"&sort=updateDate+{sort_by}"
+ f"&format=json&api_key={api_key}"
)
return await amake_request(url)View on GitHub (pinned to 3e071fcc2c)
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
Example fix
# before
res = await get_bills_by_type(bill_type='hr', start_date='2022-06-01', end_date='2023-06-01')
# after
res = []
for congress in (117, 118):
res += (await get_all_bills(congress=congress, bill_type='hr'))['bills'] Defensive patterns
Strategy: validation
Validate before calling
from datetime import date
def spans_one_congress(start: str, end: str) -> bool:
sy, ey = date.fromisoformat(start).year, date.fromisoformat(end).year
# Congress N covers [1935 + 2*(N-74), +1]; same Congress iff same derived number
return (74 + (sy - 1935) // 2) == (74 + (ey - 1935) // 2) Try / catch
try:
res = await get_bills_by_type(bill_type='hr', start_date=s, end_date=e)
except ValueError as ex:
if 'same Congress session' in str(ex):
res = []
for c in {year_to_congress(date.fromisoformat(d).year) for d in (s, e)}:
res += await get_all_bills(congress=c, bill_type='hr')
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Year must be 1935 or later.
- 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/fd19dbb2f9cf552c.
Report an issue: GitHub.