Django

Code

Ticket #4879 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

post_create signal

Reported by: Alexander Solovyov <alexander.solovyov@gmail.com> Assigned to: gav
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: sprintsept14
Cc: gav@thataddress.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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

Attachments

post_create_patch.diff (0.8 kB) - added by Alexander Solovyov <alexander.solovyov@gmail.com> on 07/14/07 13:37:12.
post_create_patch.2.diff (0.9 kB) - added by Alexander Solovyov <alexander.solovyov@gmail.com> on 07/15/07 12:46:13.
working version
post_create_patch.3.diff (0.9 kB) - added by Alexander Solovyov <alexander.solovyov@gmail.com> on 07/15/07 12:57:38.
typo fixed
post_save_with_created_kw.patch (1.1 kB) - added by gav@thataddress.com on 08/09/07 16:29:00.
Adds a "created" flag to the post_save signal.
post_save_with_created_kw_r5991.patch (1.0 kB) - added by George Vilches <gav@thataddress.com> on 08/21/07 08:26:35.
Updated patch for post_save created signal against r5991.
django_unit_test_model_signals.diff (2.6 kB) - added by George Vilches <gav@thataddress.com> on 08/21/07 08:40:14.
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@thataddress.com> on 09/14/07 07:54:32.
Post save patch + unit tests against r6184

Change History

07/14/07 13:37:12 changed by Alexander Solovyov <alexander.solovyov@gmail.com>

  • attachment post_create_patch.diff added.

07/15/07 08:21:48 changed by mtredinnick

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

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.

07/15/07 12:46:13 changed by Alexander Solovyov <alexander.solovyov@gmail.com>

  • attachment post_create_patch.2.diff added.

working version

07/15/07 12:46:50 changed by Alexander Solovyov <alexander.solovyov@gmail.com>

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

07/15/07 12:57:38 changed by Alexander Solovyov <alexander.solovyov@gmail.com>

  • attachment post_create_patch.3.diff added.

typo fixed

08/09/07 16:29:00 changed by gav@thataddress.com

  • attachment post_save_with_created_kw.patch added.

Adds a "created" flag to the post_save signal.

08/09/07 16:32:14 changed by gav@thataddress.com

  • cc set to gav@thataddress.com.

+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.

08/21/07 08:26:35 changed by George Vilches <gav@thataddress.com>

  • attachment post_save_with_created_kw_r5991.patch added.

Updated patch for post_save created signal against r5991.

08/21/07 08:40:14 changed by George Vilches <gav@thataddress.com>

  • attachment django_unit_test_model_signals.diff added.

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

08/21/07 20:54:44 changed by George Vilches <gav@thataddress.com>

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.

09/13/07 08:37:27 changed by George Vilches <gav@thataddress.com>

  • owner changed from nobody to gav.

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

09/14/07 07:54:32 changed by George Vilches <gav@thataddress.com>

  • attachment post_save_with_created_kw_r6184.patch added.

Post save patch + unit tests against r6184

09/14/07 10:11:28 changed by George Vilches <gav@thataddress.com>

  • keywords set to sprintsept14.

09/15/07 04:14:51 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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()).


Add/Change #4879 (post_create signal)




Change Properties
Action