Code

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#5422 closed (fixed)

Passing raw flag as an additional parameter to post_save & pre_save signals

Reported by: graham.carlyle@… Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: huddlej@…, jonathan.buchanan@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Signal handlers attached to pre_save & post_save signals are called when data is loaded from a fixture. If these signal handlers attempt to query/modify other records in the database then they may have problems as the database might not yet be in a consistent state if the fixture hasn't completed loading.

Work resulting from ticket #4495 avoided the calling of a custom save method when loading fixtures to avoid this same problem.

By passing the raw flag as an additional parameter to the signal handlers their implementations could decide whether to do any work and so avoid data consistency problems when the raw flag is True.

This change is unlikely to cause problems with existing signal handlers as named arguments are only passed to handlers that have those as parameters.

Attachments (2)

save-send-raw-flag.diff (900 bytes) - added by graham.carlyle@… 7 years ago.
Passes raw flag from save to pre_save & post_save signal handlers
save-send-raw-flag_v2.diff (1.8 KB) - added by graham.carlyle@… 6 years ago.
Updated patch against trunk and updated corresponding tests

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by graham.carlyle@…

Passes raw flag from save to pre_save & post_save signal handlers

comment:1 Changed 7 years ago by graham.carlyle@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Oops I meant "work resulting from ticket #4459..."

comment:2 Changed 7 years ago by anonymous

  • Cc huddlej@… added

comment:3 Changed 7 years ago by Bastian Kleineidam <calvin@…>

The patch works fine on my development servers, thanks!

Changed 6 years ago by graham.carlyle@…

Updated patch against trunk and updated corresponding tests

comment:4 Changed 6 years ago by insin

  • Cc jonathan.buchanan@… added

comment:5 Changed 6 years ago by gwilson

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

(In [7054]) Fixed #5422 -- Added a raw parameter to model pre_save and post_save signals, based on patch from graham.carlyle@maplecroft.net.

comment:6 Changed 6 years ago by gwilson

Noting that this change is backwards-compatible since django.dispatch.robustapply.robustApply checks to see what arguments and keyword arguments the receiver accepts and only calls the receiver with those arguments.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.