[Django] #30710: impossible without workarounds to see which fields changed when subscribing to signals from generic views

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #30710: impossible without workarounds to see which fields changed when subscribing to signals from generic views

Django
#30710: impossible without workarounds to see which fields changed when subscribing
to signals from generic views
-----------------------------------------+------------------------
               Reporter:  MaxR           |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  2.1
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 for example I have simple `generic view`:

 {{{
 #views.py
 class CollectorUpdate(generic.UpdateView):
     model = ReportBase
     fields = ['title', 'db', 'additionalPath', 'start_date', 'end_date',
 'reportTimestamp',
               'updMethod', 'cronStr', 'code', 'code_renew']
     template_name = 'collector/collector_update_form.html'
 }}}

 and subscribe to `post_save` signal:

 {{{
 @receiver(signal=signals.post_save, sender=ReportBase)
 def runCron(sender, **kwargs):
     """Signal handler. Run cron after post_save signal on """
     collector = kwargs.get('instance')
     updated_fields = kwargs.get('update_fields')
 }}}

 but `updated_fields`  always is `None`

 I think the problem is that in generic.UpdateView into `.save()` method it
 is necessary to register a field `field_update` with interesting for me
 fields.
 As workaround i'm using an instyance of saved object:
 {{{
  collector = kwargs.get('instance')
 }}}
 but it's looks strange and it is inconvenient. I have to do a lot of extra
 work

--
Ticket URL: <https://code.djangoproject.com/ticket/30710>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.b98ecd2740b8ff466f9e2b2d2cb9691f%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30710: impossible without workarounds to see which fields changed when subscribing to signals from generic views

Django
#30710: impossible without workarounds to see which fields changed when subscribing
to signals from generic views
-------------------------------+--------------------------------------
     Reporter:  MaxR           |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  closed
    Component:  Uncategorized  |                  Version:  2.1
     Severity:  Normal         |               Resolution:  wontfix
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 This is the expected behaviour
 ([https://docs.djangoproject.com/en/2.2/ref/signals/#django.db.models.signals.post_save
 as documented]).

 As per [https://docs.djangoproject.com/en/2.2/ref/models/instances
 /#specifying-which-fields-to-save Specifying which fields to save] the
 saved fields are only limited if you pass `update_fields`, otherwise it's
 all, so you don't need it in `post_save`.

 If you want to pass `update_fields`, override your form's `save()`
 accordingly.

--
Ticket URL: <https://code.djangoproject.com/ticket/30710#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

--
You received this message because you are subscribed to the Google Groups "Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.f5daef9c9fe2046db9dfcfc0d4620f8a%40djangoproject.com.