Skip to content

Finalized database router support#35

Open
p-r-a-v-i-n wants to merge 1 commit into
RealOrangeOne:masterfrom
p-r-a-v-i-n:confirm-db-router
Open

Finalized database router support#35
p-r-a-v-i-n wants to merge 1 commit into
RealOrangeOne:masterfrom
p-r-a-v-i-n:confirm-db-router

Conversation

@p-r-a-v-i-n
Copy link
Copy Markdown

Fixes #6


results = DBTaskResult.objects.finished().filter(backend_name=backend.alias)
results = (
DBTaskResult.objects.using(router.db_for_write(DBTaskResult))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why are you forcing this to use the writer connection? Django should route the below .count and .delete to the right place automatically.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/settings.py Outdated
Comment thread .codex Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure database routers work correctly

2 participants