Opened 14 years ago

Closed 14 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: dev
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: no UI/UX: no

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

Download all attachments as: .zip

Change History (8)

comment:1 by Alex Gaynor, 14 years ago

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 by Andrew Godwin, 14 years ago

Owner: changed from nobody to Andrew Godwin
Status: newassigned

by Andrew Godwin, 14 years ago

Attachment: 13552-take-1.diff added

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

comment:3 by Andrew Godwin, 14 years ago

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.

by Andrew Godwin, 14 years ago

Attachment: 13552-take-2.diff added

Second patch, with removal of slash and

comment:4 by Alex Gaynor, 14 years ago

Triage Stage: AcceptedReady for checkin

by Andrew Godwin, 14 years ago

Attachment: 13552-take-3.diff added

Also include an AUTHORS commit.

comment:5 by Russell Keith-Magee, 14 years ago

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