Fix cron-descriptor >= 2.0 compatibility#1009
Conversation
cron-descriptor 2.0 renamed FormatException, MissingFieldException, and WrongArgumentException to FormatError, MissingFieldError, and WrongArgumentError. Versions 2.0.3-2.0.5 only export the new names, while 2.0.6+ provides both as aliases. Use try/except ImportError to import new names first, falling back to old names for cron-descriptor <2.0. Remove the <2.0.0 version cap. Fixes celery#934
Add clarifying comment, extract get_description from try/except since it was not renamed in cron-descriptor v2.
There was a problem hiding this comment.
Pull request overview
Updates django-celery-beat to be compatible with cron-descriptor v2.x (which renamed exception classes) while retaining compatibility with v1.x, and removes the temporary dependency cap that blocked v2 upgrades.
Changes:
- Add dual-import shim in
django_celery_beat/models.pyto support both*Exception(v1) and*Error(v2) cron-descriptor exception names. - Update the
human_readableexception handling to catch the unified*Errornames. - Remove the
<2.0.0upper cap forcron-descriptorinrequirements/default.txt.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| requirements/default.txt | Removes the temporary <2.0.0 cap on cron-descriptor to allow v2.x installs. |
| django_celery_beat/models.py | Adds backward/forward-compatible exception imports and updates exception handling in human_readable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| tzdata | ||
| python-crontab>=2.3.4 | ||
| cron-descriptor>=1.2.32,<2.0.0 | ||
| cron-descriptor>=1.2.32 |
There was a problem hiding this comment.
cron-descriptor is now unbounded above. Given the project already caps other major dependencies (e.g., celery<6.0, Django<6.1) and cron-descriptor has already introduced a breaking change at v2, consider adding an upper bound like <3.0.0 to avoid an untested future major release breaking installs again while still allowing v2.x.
| cron-descriptor>=1.2.32 | |
| cron-descriptor>=1.2.32,<3.0.0 |
There was a problem hiding this comment.
Good point — added <3.0.0 upper bound in 088355d to stay consistent with the other capped dependencies.
Cap at <3.0.0 to stay consistent with other dependencies in the project and guard against future breaking changes.
auvipy
left a comment
There was a problem hiding this comment.
please check the build failures
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1009 +/- ##
==========================================
+ Coverage 87.58% 87.64% +0.06%
==========================================
Files 32 32
Lines 1007 1012 +5
Branches 81 81
==========================================
+ Hits 882 887 +5
Misses 107 107
Partials 18 18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cron-descriptor v2 changed the default to 24h format, causing test_long_name to fail. Explicitly set use_24hour_time_format=False via a module-level Options constant.
- Verify human_readable uses 12-hour format (PM for hour 14) - Cover FormatError, MissingFieldError, WrongArgumentError fallback paths
|
Fixed the CI failure — Changes in this push:
|
for more information, see https://pre-commit.ci
Replace @patch decorator with `with patch(...)` context manager to avoid unused fixture parameter lint error.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from cron_descriptor import (FormatException as FormatError, | ||
| MissingFieldException as MissingFieldError, | ||
| WrongArgumentException as WrongArgumentError) | ||
|
|
There was a problem hiding this comment.
This change stops exporting the old *Exception symbols from django_celery_beat.models (they were previously imported directly). If any downstream code imports FormatException/MissingFieldException/WrongArgumentException from this module, it will now break. Consider keeping backward-compatible aliases (e.g., bind the old names to the new *Error symbols) so both naming schemes continue to work.
| # Backwards compatibility: re-export legacy *Exception names | |
| FormatException = FormatError | |
| MissingFieldException = MissingFieldError | |
| WrongArgumentException = WrongArgumentError |
There was a problem hiding this comment.
These exceptions are internal to cron-descriptor and are only used privately inside human_readable. They were never part of django-celery-beat's public API — no downstream code should be importing them from django_celery_beat.models.
If anyone needs these exceptions, the correct import is directly from cron_descriptor, not from this module. Adding re-export aliases would actually make things worse by encouraging an incorrect import path.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@auvipy Build failures are fixed — all 18 CI jobs pass (Python 3.9–3.14, Django 3.2–6.0). The last push adds Ready for re-review when you get a chance. |
Summary
cron-descriptor2.0 renamed exception classes (FormatException→FormatError, etc.). PR #935 temporarily capped the dependency to<2.0.0to avoidImportErroron deploy (#937). This PR applies the real fix:*Exceptionnames) and v2.x (new*Errornames)<2.0.0version cap fromrequirements/default.txtThe
except ImportError:fallback is already excluded from coverage reporting inpyproject.toml(line 136), so patch coverage should not be affected.Related
ImportErrorcrash on deployCompatibility matrix
*Exception(old)*Error(new)Test plan
test_run_taskwhich requires RabbitMQ)rufflinter passes