OpenBB-finance/OpenBB · error · OpenBBError
Invalid year. Year cannot be in the future.
Error message
Invalid year. Year cannot be in the future.
What it means
Second branch of the same year validator: rejects years greater than datetime.now().year because future bulletins do not exist yet. Raised as OpenBBError wrapping a ValueError during pydantic validation, so no request is made.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/models/weather_bulletin.py:29
WeatherBulletinQueryParams,
)
from pydantic import ConfigDict, field_validator
class GovernmentUsWeatherBulletinQueryParams(WeatherBulletinQueryParams):
"""US Government Weather Bulletin Query Params.
Source: https://esmis.nal.usda.gov/publication/weekly-weather-and-crop-bulletin
"""
@field_validator("year")
@classmethod
def _validate_year(cls, value: int) -> int:
"""Validate year."""
if value < 1974:
raise ValueError("Year must not be before 1974.")
if value > datetime.now().year:
raise OpenBBError(ValueError("Invalid year. Year cannot be in the future."))
return value
class GovernmentUsWeatherBulletinData(WeatherBulletinData):
"""US Government Weather Bulletin Data.
The Weekly Weather and Crop Bulletin is released by 4:00 p.m. on the second workday of each week.
The Bulletin includes the National Summary, State Stories, current data for weather, temperature and precipitation
and international agricultural weather. The full report is jointly published by the National Oceanic
and Atmospheric Administration of the U.S. Department of Commerce, the National Agricultural Statistics Service,
and the World Agricultural Outlook Board.
"""
model_config = ConfigDict(
extra="ignore",
)
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use the current or a past year.
- Derive the year dynamically (datetime.now().year) instead of hardcoding.
- For year-boundary jobs, compute the year at call time, not at job-definition time.
Example fix
# before res = obb.economy.gov.weather_bulletin(year=2027) # today is 2026 # after from datetime import datetime res = obb.economy.gov.weather_bulletin(year=datetime.now().year)
Defensive patterns
Strategy: validation
Validate before calling
from datetime import datetime
def valid_bulletin_year(y: int) -> bool:
return 1974 <= y <= datetime.now().year Prevention
- Compute the year at call time with datetime.now().year.
- Watch year-boundary timing in scheduled jobs (UTC vs local).
When it happens
Trigger: Calling weather_bulletin with next year's value; code that computes year + 1; long-running processes started in December that execute in January with a stale computed year.
Common situations: Off-by-one year arithmetic; hardcoded years that go stale; timezone differences where local year is behind/ahead of the server's now().
Related errors
- Year must not be before 1974.
- Invalid URL '{url}'. Only URLs from 'esmis.nal.usda.gov' are
- Invalid URL '{url}'. Only PDF documents are supported.
- At least one extension type must be selected.
- Incorrect email or password
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/008e1138dd65c58b.
Report an issue: GitHub.