-
Notifications
You must be signed in to change notification settings - Fork 211
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
feat: raw delete expired instead of Queryset.delete
#235
Conversation
This is avoid unncessary loading of objects in-memory in certain conditions
There is already a test that checks if the |
@auvipy - Requesting review |
thanks for the pr |
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.
I still want to see some new unit tests
@auvipy unit test against |
@@ -88,7 +88,7 @@ def get_all_expired(self, expires): | |||
def delete_expired(self, expires): | |||
"""Delete all expired results.""" | |||
with transaction.atomic(): | |||
self.get_all_expired(expires).delete() | |||
raw_delete(queryset=self.get_all_expired(expires)) |
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.
another thing i want to be assured that running makemigrations detect any change in migrations
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.
I added similar test for django-silk
two days back, where i simply called management command makemigrations silk --check --dry-run
- if there are pending migrations then it returns with exit code 1.
Should we implement the same?
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.
that would be great!
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.
There is already this test which does that.
django-celery-results/t/unit/test_migrations.py
Lines 26 to 32 in 0a00044
def test_models_match_migrations(self): | |
"""Make sure that no model changes exist. | |
This logic is taken from django's makemigrations.py file. | |
Here just detect if model changes exist that require | |
a migration, and if so we fail. | |
""" |
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.
should we replace this with call_command
thing i mentioned above? One advantage is that it is a higher level Django API - changes in Django internal will not affect the test - until only the command behaviour is changed.
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.
which part do you want to replace with what? can you elaborate please?
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.
Running makemigrations django_celery_results --check --dry-run
command inside the test as mentioned above.
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.
ok
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.
made those changes. Please review.
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.
commit - 113ac2e
@@ -88,7 +88,7 @@ def get_all_expired(self, expires): | |||
def delete_expired(self, expires): |
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.
tests for this method needs to be updated as well
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.
what kind of update? the current test looks sufficient to me.
…calling internal logic of `makemigrations` to check if no pending migrations
can you check why CI is failing please |
@auvipy Looks like the CI is stuck. |
CI is running green :D |
going to merge this for now. future improvements are always welcome |
I have a django model with a ForeignKey to TaskResult, and we set the |
can you please share more detail? |
I have a django model named class MyTaskResult(models.Model):
result = models.OneToOneField(
TaskResult,
on_delete=models.CASCADE,
verbose_name='TaskResult',
)
# other fields and it works well when django-celery-results at 2.2.0. from datetime import timedelta
from django_celery_results.models import TaskResult
t = timedelta(minutes=1)
TaskResult.objects.delete_expired(t) I got this error: django.db.utils.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (..., CONSTRAINT `..._result_id_bbca4d3d_fk_django_ce` FOREIGN KEY (`result_id`) REFERENCES `django_celery_results_taskresult` (`id`))')" I think the builtin task In 2.2.0, |
can you help to partially revert this manually? or provide a bettter mechanism?? |
Maybe can add a config key to switch? I saw it in here, but not in this mr |
And I think the default behavior should be to use queryset's delete instead of |
I will be happy to accept a PR with partial revert of the PR[raw-delete part] |
I will submit this at a later date :) |
This is avoid unncessary loading of objects in-memory in certain conditions.
From Django docs:
Closes #232