Sure I guess you _could_ take a generic signals approach to handling all modify operations, but for each operation context is important. The state of the object(s) matters when performing operations. The `pre_save` and `post_save` signals for example have a `created` flag which allows for filtering out the new objects versus existing ones. Likewise, having a distinct pair of delete signals ensures you don't make the mistake of performing operations on objects that are now deleted.
Ultimately my request is for batch or bulk-level signals. Up until recently, the lack of API for bulk operations in the ORM has been a non-starter for doing any kind of ETL for large amounts of data (not that I ever expected Django to have suitable APIs or performance for ETL pipelines). But now using it's at least reasonable to argue to include in a pipeline if there would be a suitable set of bulk-level signals when doing batch inserts, updates and deletes. On Sunday, March 25, 2012 6:23:46 PM UTC-4, Anssi Kääriäinen wrote: > > A somewhat different proposal is in ticket #17824: Add generic > pre/post_modify signal. I think the generic > "object modified" signals would fit your use case very well. > > The idea is that there would be just one signal which would be fired for > any data modifying ORM operation. > The arguments for it: > - fired for every operation modifying data > - one signal to listen to for all data modifications > The likely counter-arguments: > - duplicates the existing signals > - the callbacks end up being a big "switch statement", and thus you end > up separating save, delete etc > anyways. > - the API isn't good enough > > From performance perspective there should be no big problems: the signal > is given an iterable as > "objs_modified" argument. For .update() for example, where you don't want > to fetch all the objects for > performance reasons, you could just pass qs.filter(update_filters) as the > modified objects. This way > there would be no performance penalty, except if there is actual use of > the signal. > > I would like to see a generic pre/post modify signal, as I think it is > much easier to use than using > the pre/post save/delete + m2m_changed signals. However, I do not feel > strongly at all about this, just > something I would find useful. I believe having total control of all data > modifying operations using Django > signals would be a welcome addition for many users. > > - Anssi > ________________________________________ > From: django-developers@googlegroups.com<django-developers@googlegroups.com>[ > django-developers@googlegroups.com <django-developers@googlegroups.com>] > On Behalf Of Byron Ruth [bjr...@gmail.com] > Sent: Sunday, March 25, 2012 17:46 > To: django-developers@googlegroups.com<django-developers@googlegroups.com> > Subject: Add signals for QuerySet bulk operations such as `delete`, > `update, `bulk_create` > > My use case is for regenerating aggregate data cache at a table level. > Simply calling a single signal after a bulk operation is complete would > enable invalidating such aggregate cache. There is not a very clean > alternate solution to this problem unless using database triggers which > calls an external script that invalidates the cache. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-developers/-/DAaTRIau8h8J<https://groups.google.com/d/msg/django-developers/-/DAaTRIau8h8J> > . > To post to this group, send email to > django-developers@googlegroups.com<django-developers@googlegroups.com> > . > To unsubscribe from this group, send email to > django-developers+unsubscribe@googlegroups.com<django-developers%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en<http://groups.google.com/group/django-developers?hl=en> > . > > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/RCufSikz0cEJ. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.