celery/celery · error · ValueError

Argument event "{event}" is invalid, must be one of {all_eve

Error message

Argument event "{event}" is invalid, must be one of {all_events}.

What it means

Raised as ValueError by solar.__init__ when the event argument is not one of the supported solar events. Celery's solar schedule delegates to PyEphem and supports a fixed enumeration: dawn_astronomical, dawn_civil, dawn_nautical, sunrise, solar_noon, sunset, dusk_civil, dusk_nautical, dusk_astronomical.

Source

Thrown at celery/schedules.py:801

        'dawn_civil': True,
        'sunrise': False,
        'solar_noon': False,
        'sunset': False,
        'dusk_civil': True,
        'dusk_nautical': True,
        'dusk_astronomical': True,
    }

    def __init__(self, event: str, lat: int | float, lon: int | float, **
                 kwargs: Any) -> None:
        self.ephem = __import__('ephem')
        self.event = event
        self.lat = lat
        self.lon = lon
        super().__init__(**kwargs)

        if event not in self._all_events:
            raise ValueError(SOLAR_INVALID_EVENT.format(
                event=event, all_events=', '.join(sorted(self._all_events)),
            ))
        if lat < -90 or lat > 90:
            raise ValueError(SOLAR_INVALID_LATITUDE.format(lat=lat))
        if lon < -180 or lon > 180:
            raise ValueError(SOLAR_INVALID_LONGITUDE.format(lon=lon))

        cal = self.ephem.Observer()
        cal.lat = str(lat)
        cal.lon = str(lon)
        cal.elev = 0
        cal.horizon = self._horizons[event]
        cal.pressure = 0
        self.cal = cal

        self.method = self._methods[event]
        self.use_center = self._use_center_l[event]

View on GitHub (pinned to 571efe8120)

Solutions

  1. Use one of the exact lowercase event names the message lists (dawn_astronomical, dawn_civil, dawn_nautical, sunrise, solar_noon, sunset, dusk_civil, dusk_nautical, dusk_astronomical).
  2. Source the event string from a constant/enum in your config to avoid typos.
  3. Lower-case and strip whitespace on the input before constructing the schedule.

Example fix

# before
solar('sunrise', 40, -3)  # typoed as 'sunrise00'
# after
from celery.schedules import solar
solar('sunrise', 40, -3)
Defensive patterns

Strategy: validation

Validate before calling

VALID_SOLAR_EVENTS = {
    'dawn_astronomical','dawn_civil','dawn_nautical',
    'sunrise','solar_noon','sunset',
    'dusk_civil','dusk_nautical','dusk_astronomical',
}

def is_valid_event(event: str) -> bool:
    return isinstance(event, str) and event.strip().lower() in VALID_SOLAR_EVENTS

Type guard

from typing import Literal
SolarEvent = Literal['dawn_astronomical','dawn_civil','dawn_nautical','sunrise','solar_noon','sunset','dusk_civil','dusk_nautical','dusk_astronomical']

Try / catch

try:
    solar(event, lat, lon)
except ValueError as e:
    if 'Argument event' in str(e):
        event = 'sunrise'
        solar(event, lat, lon)
    else:
        raise

Prevention

When it happens

Trigger: solar('sunrise00', 40, -3), solar('moonrise', 50, 10), solar('SUNRISE', ...) with wrong case, or any event name not in _all_events. Case-sensitive exact match required.

Common situations: Typing the event name, using an unsupported phenomenon (e.g. moonrise), or assuming case-insensitivity. The valid set is listed in the message via {all_events}.

Related errors


AI-assisted analysis of celery/celery@571efe8120 (2026-08-04). Data as JSON: /data/errors/00233351a3600814.json. Report an issue: GitHub.