Opened 5 years ago

Closed 4 years ago

#26170 closed Bug (fixed)

ModelAdmin add/change/delete views always run transaction on default database

Reported by: juntatalor Owned by: nobody
Component: contrib.admin Version: master
Severity: Normal Keywords: admin multi database
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When settings.DATABASES 'default' key is set to empty dict Django Admin tries to perform transaction.atomic on dummy database, and it ends in raising exception, when trying to change, add or delete record.

ModelAdmin functions that use transaction.atomic:
https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1393
https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1660

"using" argument (taken from db routers) should be specified for transaction.atomic

Patch: https://github.com/django/django/pull/6076

Change History (4)

comment:1 Changed 5 years ago by Tim Graham

Needs tests: set
Summary: Admin.ModelAdmin incorrectly works with multiple databasesModelAdmin add/change/delete views always run transaction on default database
Triage Stage: UnreviewedAccepted

Patch needs tests. Looks like this also affects django/contrib/auth/admin.py.

comment:2 Changed 4 years ago by Simon Charette

Needs tests: unset
Patch needs improvement: set
Version: 1.9master

The new PR includes tests but doesn't deal with the django/contrib/auth/admin.py instance yet.

comment:3 Changed 4 years ago by Tim Graham

Patch needs improvement: unset

comment:4 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 9459ec8:

Fixed #26170 -- Made ModelAdmin views run transactions on the correct database.

Thanks juntatalor for the initial patch.

Note: See TracTickets for help on using tickets.
Back to Top