-
Notifications
You must be signed in to change notification settings - Fork 464
Abstract Django DB Models #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blbuford
wants to merge
13
commits into
celery:main
Choose a base branch
from
pingintel:feature/abstract-models-import
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
49d9331
Support for abstract base models improved. (#516)
diegocastrum b974ef9
Merge branch 'master' into feature/abstract-models
diegocastrum b12052b
Fixed a wrong import for validators
diegocastrum e1b41aa
Exporting 'crontab_schedule_celery_timezone' from 'models.abstract'
diegocastrum a0a7b13
Fixed a wrong export introduced in prev commit
diegocastrum 742ee54
Bypass de default models used by `django_celery_beat.scheduler` (#516)
diegocastrum 0e5844f
Merge remote-tracking branch 'diegocastrum/feature/abstract-models' i…
blbuford bf9b408
Make UTS pass
blbuford b25089f
namespace the lazy FKs
blbuford 1b4b652
precommit
blbuford a936824
Cut down on unnecessary diff
blbuford 245e324
test_helpers for code cov
blbuford 2bf1a84
reduce schedulers.py diff
blbuford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,4 @@ coverage.xml | |
.python-version | ||
venv | ||
.env | ||
.vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
from django.apps import apps | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
def crontabschedule_model(): | ||
"""Return the CrontabSchedule model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_CRONTABSCHEDULE_MODEL"): | ||
from .models.generic import CrontabSchedule | ||
|
||
return CrontabSchedule | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_CRONTABSCHEDULE_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_CRONTABSCHEDULE_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_CRONTABSCHEDULE_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_CRONTABSCHEDULE_MODEL}' that has not " | ||
"been installed" | ||
) | ||
|
||
|
||
def intervalschedule_model(): | ||
"""Return the IntervalSchedule model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_INTERVALSCHEDULE_MODEL"): | ||
from .models.generic import IntervalSchedule | ||
|
||
return IntervalSchedule | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_INTERVALSCHEDULE_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_INTERVALSCHEDULE_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_INTERVALSCHEDULE_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_INTERVALSCHEDULE_MODEL}' that has not " | ||
"been installed" | ||
) | ||
|
||
|
||
def periodictask_model(): | ||
"""Return the PeriodicTask model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_PERIODICTASK_MODEL"): | ||
from .models.generic import PeriodicTask | ||
|
||
return PeriodicTask | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_PERIODICTASK_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_PERIODICTASK_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_PERIODICTASK_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_PERIODICTASK_MODEL}' that has not been " | ||
"installed" | ||
) | ||
|
||
|
||
def periodictasks_model(): | ||
"""Return the PeriodicTasks model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_PERIODICTASKS_MODEL"): | ||
from .models.generic import PeriodicTasks | ||
|
||
return PeriodicTasks | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_PERIODICTASKS_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_PERIODICTASKS_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_PERIODICTASKS_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_PERIODICTASKS_MODEL}' that has not been " | ||
"installed" | ||
) | ||
|
||
|
||
def solarschedule_model(): | ||
"""Return the SolarSchedule model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_SOLARSCHEDULE_MODEL"): | ||
from .models.generic import SolarSchedule | ||
|
||
return SolarSchedule | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_SOLARSCHEDULE_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_SOLARSCHEDULE_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_SOLARSCHEDULE_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_SOLARSCHEDULE_MODEL}' that has not been " | ||
"installed" | ||
) | ||
|
||
|
||
def clockedschedule_model(): | ||
"""Return the ClockedSchedule model that is active in this project.""" | ||
if not hasattr(settings, "CELERY_BEAT_CLOCKEDSCHEDULE_MODEL"): | ||
from .models.generic import ClockedSchedule | ||
|
||
return ClockedSchedule | ||
|
||
try: | ||
return apps.get_model(settings.CELERY_BEAT_CLOCKEDSCHEDULE_MODEL) | ||
except ValueError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_CLOCKEDSCHEDULE_MODEL must be of the form " | ||
"'app_label.model_name'" | ||
) | ||
except LookupError: | ||
raise ImproperlyConfigured( | ||
"CELERY_BEAT_CLOCKEDSCHEDULE_MODEL refers to model " | ||
f"'{settings.CELERY_BEAT_CLOCKEDSCHEDULE_MODEL}' that has not " | ||
"been installed" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .abstract import DAYS, crontab_schedule_celery_timezone | ||
from .generic import (ClockedSchedule, CrontabSchedule, IntervalSchedule, | ||
PeriodicTask, PeriodicTasks, SolarSchedule) | ||
|
||
__all__ = [ | ||
"ClockedSchedule", | ||
"CrontabSchedule", | ||
"IntervalSchedule", | ||
"PeriodicTask", | ||
"PeriodicTasks", | ||
"SolarSchedule", | ||
"crontab_schedule_celery_timezone", | ||
"DAYS", | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The model‐fetching functions in this file have nearly identical logic. Consider extracting the common pattern into a single helper that takes the setting name and default import path to reduce duplication.
Copilot uses AI. Check for mistakes.