Skip to content

Commit

Permalink
Ensure return value is correctly exposed using database backend
Browse files Browse the repository at this point in the history
It seems the return value was always `None`, regardless of if the task actually returned a value.

Fixes #131
  • Loading branch information
RealOrangeOne committed Dec 27, 2024
1 parent f3456b3 commit 22d51b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions django_tasks/backends/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def task_result(self) -> "TaskResult[T]":

object.__setattr__(task_result, "_exception_class", exception_class)
object.__setattr__(task_result, "_traceback", self.traceback or None)
object.__setattr__(task_result, "_return_value", self.return_value)

return task_result

Expand Down
4 changes: 4 additions & 0 deletions tests/tests/test_database_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_refresh_result(self) -> None:
status=ResultStatus.SUCCEEDED,
started_at=timezone.now(),
finished_at=timezone.now(),
return_value=42,
)

self.assertEqual(result.status, ResultStatus.NEW)
Expand All @@ -139,6 +140,7 @@ def test_refresh_result(self) -> None:
self.assertIsNotNone(result.finished_at)
self.assertEqual(result.status, ResultStatus.SUCCEEDED)
self.assertTrue(result.is_finished)
self.assertEqual(result.return_value, 42)

async def test_refresh_result_async(self) -> None:
result = await default_task_backend.aenqueue(
Expand All @@ -149,6 +151,7 @@ async def test_refresh_result_async(self) -> None:
status=ResultStatus.SUCCEEDED,
started_at=timezone.now(),
finished_at=timezone.now(),
return_value=42,
)

self.assertEqual(result.status, ResultStatus.NEW)
Expand All @@ -160,6 +163,7 @@ async def test_refresh_result_async(self) -> None:
self.assertIsNotNone(result.finished_at)
self.assertEqual(result.status, ResultStatus.SUCCEEDED)
self.assertTrue(result.is_finished)
self.assertEqual(result.return_value, 42)

def test_get_missing_result(self) -> None:
with self.assertRaises(ResultDoesNotExist):
Expand Down

0 comments on commit 22d51b3

Please sign in to comment.