Skip to content

Commit f57dbcf

Browse files
authored
fix: allow for custom states in status field (#407)
* fix: allow for custom states in status field From #366 (comment) Thanks to @cdevacc1 for the idea. I just decided to write up the PR as it only takes a couple of minutes. This should resolve the bug where custom states are not shown at all in the admin panel. * Add database tests for custom states From #407 (comment) Thanks to @AllexVeldman for the tests! * Add new migrations for custom states * Fix format lint
1 parent c236191 commit f57dbcf

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 5.1.7 on 2025-03-08 06:18
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
(
10+
"django_celery_results",
11+
"0013_taskresult_django_cele_periodi_1993cf_idx"
12+
),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name="taskresult",
18+
name="status",
19+
field=models.CharField(
20+
default="PENDING",
21+
help_text="Current state of the task being run",
22+
max_length=50,
23+
verbose_name="Task State",
24+
),
25+
),
26+
]

django_celery_results/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class TaskResult(models.Model):
5151
'used with the task'))
5252
status = models.CharField(
5353
max_length=50, default=states.PENDING,
54-
choices=TASK_STATE_CHOICES,
5554
verbose_name=_('Task State'),
5655
help_text=_('Current state of the task being run'))
5756
worker = models.CharField(

t/unit/backends/test_database.py

+13
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,19 @@ def test_backend_result_extended_is_false(self):
955955
assert tr.task_args is None
956956
assert tr.task_kwargs is None
957957

958+
def test_custom_state(self):
959+
tid = uuid()
960+
961+
assert self.b.get_status(tid) == states.PENDING
962+
963+
self.b.store_result(tid, state="Progress", result={"progress": 10})
964+
assert self.b.get_status(tid) == "Progress"
965+
assert self.b.get_result(tid) == {"progress": 10}
966+
967+
self.b.mark_as_done(tid, 42)
968+
assert self.b.get_status(tid) == states.SUCCESS
969+
assert self.b.get_result(tid) == 42
970+
958971

959972
class DjangoCeleryResultRouter:
960973
route_app_labels = {"django_celery_results"}

0 commit comments

Comments
 (0)