Opened 8 years ago

Closed 8 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: dev
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 by Tim Graham, 8 years ago

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 by Simon Charette, 8 years ago

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 by Tim Graham, 8 years ago

Patch needs improvement: unset

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

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