Opened 5 years ago

Closed 5 years ago

#13552 closed (fixed)

pre_save & post_save model signals should also specify database to save

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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by andrewgodwin

  • Owner changed from nobody to andrewgodwin
  • Status changed from new to assigned

Changed 5 years ago by andrewgodwin

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

comment:3 Changed 5 years ago by andrewgodwin

  • 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 5 years ago by andrewgodwin

Second patch, with removal of slash and

comment:4 Changed 5 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

Changed 5 years ago by andrewgodwin

Also include an AUTHORS commit.

comment:5 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(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