Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@

import timezone_field
from celery import current_app, schedules
from cron_descriptor import (FormatException, MissingFieldException,
WrongArgumentException, get_description)

try:
Copy link
Contributor

@cclauss cclauss Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
try: # Python >= 3.11 can use cron_descriptor >= 2.0 which uses *Error exceptions.

We need a comment here explaining why.

Or perhaps in #935 we should just pin the dependency to >= 2.0 and just use *Error instead of try / except.

EDIT: #938 proves that the above suggestion will not work. We need try / except because cron_descriptor v2 only supports Python >= v3.11.

@Salamek

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cron_descriptor 2.0.5 supports Python 3.9 - 3.13...

from cron_descriptor import (FormatError, MissingFieldError,
WrongArgumentError, get_description)
except ImportError: # Python < 3.11 must use cron_descriptor < 2.0 which uses *Exception exceptions.
from cron_descriptor import FormatException as FormatError
from cron_descriptor import MissingFieldException as MissingFieldError
from cron_descriptor import WrongArgumentException as WrongArgumentError

from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned, ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
Expand Down Expand Up @@ -340,9 +347,9 @@ def human_readable(self):
try:
human_readable = get_description(cron_expression)
except (
MissingFieldException,
FormatException,
WrongArgumentException
MissingFieldError,
FormatError,
WrongArgumentError
):
return f'{cron_expression} {str(self.timezone)}'
return f'{human_readable} {str(self.timezone)}'
Expand Down
Loading