Opened 6 years ago

Closed 6 years ago

#13552 closed (fixed)

pre_save & post_save model signals should also specify database to save

Reported by: Mandx Owned by: Andrew Godwin
Component: Database layer (models, ORM) Version: master
Severity: Keywords: signals multi-db pre_save post_save
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The pre_save & post_save model signals should also specify on which database the object will be saved. Also, should be possible to connect to model signals on a specific database.

Something like:

from django.db.models.signals import pre_save
from myapp.models import MyModel

def my_default_handler(sender, **kwargs):
    # Do something on default db
    ...

def my_alternate_handler(sender, **kwargs):
    # Do something on alternate db
    ...

pre_save.connect(my_default_handler, sender=MyModel, database='default_db')
pre_save.connect(my_alternate_handler, sender=MyModel, database='alternate_db')

Attachments (3)

13552-take-1.diff (14.0 KB) - added by Andrew Godwin 6 years ago.
Patch that adds "using" keyword for *_save, *_delete, m2m_changed
13552-take-2.diff (14.0 KB) - added by Andrew Godwin 6 years ago.
Second patch, with removal of slash and
13552-take-3.diff (14.3 KB) - added by Andrew Godwin 6 years ago.
Also include an AUTHORS commit.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by Alex Gaynor

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Weeell, we can't add a param to the connect method, since Signal's don't know about models, or databases, or anything like that. However, the DB should be a param to the actual signal invocation so one can filter out the calls they want.

comment:2 Changed 6 years ago by Andrew Godwin

Owner: changed from nobody to Andrew Godwin
Status: newassigned

Changed 6 years ago by Andrew Godwin

Attachment: 13552-take-1.diff added

Patch that adds "using" keyword for *_save, *_delete, m2m_changed

comment:3 Changed 6 years ago by Andrew Godwin

Has patch: set

I've attached a patch that implements a "using" keyword for pre_save, post_save, pre_delete, post_delete, and m2m_changed, along with modified docs and tests.

Changed 6 years ago by Andrew Godwin

Attachment: 13552-take-2.diff added

Second patch, with removal of slash and

comment:4 Changed 6 years ago by Alex Gaynor

Triage Stage: AcceptedReady for checkin

Changed 6 years ago by Andrew Godwin

Attachment: 13552-take-3.diff added

Also include an AUTHORS commit.

comment:5 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [13538]) Fixed #13552 -- Added a 'using' parameter to database signals. Thanks to gmandx for the suggestion, and Andrew Godwin for the patch.

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