Finalized database router support#35
Conversation
|
|
||
| results = DBTaskResult.objects.finished().filter(backend_name=backend.alias) | ||
| results = ( | ||
| DBTaskResult.objects.using(router.db_for_write(DBTaskResult)) |
There was a problem hiding this comment.
Question: Why are you forcing this to use the writer connection? Django should route the below .count and .delete to the right place automatically.
There was a problem hiding this comment.
Thanks for spotting.
def test_prune_dry_run_uses_write_router_database(self) -> None:
result = test_tasks.noop_task.enqueue()
DBTaskResult.objects.using("secondary").filter(id=result.id).update(
status=TaskResultStatus.SUCCESSFUL,
finished_at=timezone.now(),
)
stdout = StringIO()
call_command(
"prune_db_task_results",
verbosity=3,
min_age_days=0,
dry_run=True,
stdout=stdout,
)
self.assertEqual(DBTaskResult.objects.using("secondary").count(), 1)
self.assertIn("Would delete 1 task result(s)", stdout.getvalue())
In this testcase I was calling prune_db_task_results command . so according the router setting it will fetch results from default database. In the test i suppose to show prune command output that there is 1 task would delete which from secondary database.
when i ran the prune_db_task_results command it will select db_for_read database to retrive the task results from default db where no records were created or present. so i wanted it should show 1 task to be deleted , that's why i explictly wrote. so it was wrong.
745bd12 to
98a93fc
Compare
98a93fc to
2e53727
Compare
Fixes #6