#35520: ModelAdmin uses incorrect database in change and delete views
-----------------------------------------+-----------------------------
Reporter: Jake Howard | Owner: Jake Howard
Type: Bug | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+-----------------------------
In `ModelAdmin.delete_view` and `ModelAdmin.changelist_view`, the
transaction is hardcoded to use `db_for_write`, even if the request is
read-only (eg `GET`). This potentially results in the wrong database being
selected (or errors if `db_for_write` is used to prevent writing to
models).
I propose modifying these calls to use `db_for_read` if the request is
read-only (`request.method in ("GET", "HEAD", "OPTIONS", "TRACE")`). Most
users won't notice the difference, as the same database will be selected.
But those who are using a custom router will get the database they expect.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35520>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.