Opened 8 years ago

Closed 8 years ago

#4879 closed (fixed)

post_create signal

Reported by: Alexander Solovyov <alexander.solovyov@…> Owned by: gav
Component: Database layer (models, ORM) Version: master
Severity: Keywords: sprintsept14
Cc: gav@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Patch adds post_create signal to model's save() method. This signal is useful to interact with newly created objects.

Attachments (7)

post_create_patch.diff (870 bytes) - added by Alexander Solovyov <alexander.solovyov@…> 8 years ago.
post_create_patch.2.diff (896 bytes) - added by Alexander Solovyov <alexander.solovyov@…> 8 years ago.
working version
post_create_patch.3.diff (897 bytes) - added by Alexander Solovyov <alexander.solovyov@…> 8 years ago.
typo fixed
post_save_with_created_kw.patch (1.1 KB) - added by gav@… 8 years ago.
Adds a "created" flag to the post_save signal.
post_save_with_created_kw_r5991.patch (1.0 KB) - added by George Vilches <gav@…> 8 years ago.
Updated patch for post_save created signal against r5991.
django_unit_test_model_signals.diff (2.6 KB) - added by George Vilches <gav@…> 8 years ago.
Unit test for all model signals, including testing the post_save created keyword
post_save_with_created_kw_r6184.patch (3.8 KB) - added by George Vilches <gav@…> 8 years ago.
Post save patch + unit tests against r6184

Download all attachments as: .zip

Change History (14)

Changed 8 years ago by Alexander Solovyov <alexander.solovyov@…>

comment:1 Changed 8 years ago by mtredinnick

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

There was a general consensus in a recent django-dev thread about this. No core developer spoke against it. The only question is whether to make it a new signal, or a flag attached to the post_save signal (signal emissions are not free). I'll have to rummage through the archives. Marking this as "accepted" though, since it's reasonable.

Changed 8 years ago by Alexander Solovyov <alexander.solovyov@…>

working version

comment:2 Changed 8 years ago by Alexander Solovyov <alexander.solovyov@…>

First version does not work if PK value is not set.

Changed 8 years ago by Alexander Solovyov <alexander.solovyov@…>

typo fixed

Changed 8 years ago by gav@…

Adds a "created" flag to the post_save signal.

comment:3 Changed 8 years ago by gav@…

  • Cc gav@… added

+1 to mtredinnick's idea for just adding a flag to the post_save signal. The patch I attached does exactly this, and uses a variable that already existed in the save() method that held this information anyway (it was missing one place it needed to be set, so the patch handles that as well), so the additional overhead should be nothing.

Changed 8 years ago by George Vilches <gav@…>

Updated patch for post_save created signal against r5991.

Changed 8 years ago by George Vilches <gav@…>

Unit test for all model signals, including testing the post_save created keyword

comment:4 Changed 8 years ago by George Vilches <gav@…>

The django_unit_test_model_signals.diff includes a unit tests for the Django test suite covering the following signals:

pre_save
post_save
pre_delete
post_delete

It verifies that these signals fire in the proper order, that they have the expected instance of the model, and that the created flag on post_save is correctly set.

As far as I could tell, tests for these signals do not exist anywhere.

comment:5 Changed 8 years ago by George Vilches <gav@…>

  • Owner changed from nobody to gav

I'll take responsibility for cleaning up this ticket for the sprint.

Changed 8 years ago by George Vilches <gav@…>

Post save patch + unit tests against r6184

comment:6 Changed 8 years ago by George Vilches <gav@…>

  • Keywords sprintsept14 added

comment:7 Changed 8 years ago by mtredinnick

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

(In [6269]) Fixed #4879 -- Added 'created' arg to post_save signal. This is True is a new object is created. Patch from George Vilches.

Fully backwards compatible, because signal receivers do not have to be able to accept all the arguments (thankyou, robust_apply()).

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