Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

View: New views
5 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:        
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by anonymous):

 @glassfordm: Is it possible that you forgot to `svn add` your tests before
 making the diff? I can't find any `on_delete` related tests, except a
 handful of low level tests for `CollectedFields`.

 The patch I just attached is based on `on_delete_on_update-r11620.diff`. I
 made the following changes:

  * Removed checks for `default` and `null` in `_handle_sub_obj()` (as
 these are static properties of fields and already checked in
 `contribute_to_class()`). These checks should perhaps be moved to
 `django.core.management.validation`.

  * Moved instance-update and sql-update code inside `CollectedFields` so
 the actual data structure doesn't have to be known to code outside. Is
 there a reason field updates are not simply collected in
 `CollectedObjects`, too?

  * Changed how update queries are performed: instead of one per instance,
 it now uses one (batch) per field. Except for corner cases (more than
 GET_ITERATOR_CHUNK_SIZE foreign keys on a single model affected), this
 results in fewer queries.

  * Added a pony of mine: `on_delete=DO_NOTHING`, which would help with
 #10829.

 I didn't write any tests (bad), but all existing tests pass. Which
 hopefully means that at least I haven't broken CASCADE and SET_NULL.

 Regarding stale related object caches, I'd do nothing special. Django
 currently doesn't refresh them, so any change here (for SET_NULL or
 CASCADE) would be backwards incompatible. And there is no guarantee the
 cache won't be stale again, when `_handle_sub_obj()` is called anyway.
 So this is a documentation issue with `Model.delete()` at best, since
 `QuerySet.delete()` always uses "fresh" data.

--
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:28>
Django <http://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 post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Parent Message unknown Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:        
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by emulbreh):

 Changes between 7539.on_delete.diff and 7539.on_delete.r11706.diff:

  * Added tests.

  * Replaced class based constants with callables that do what
 `_handle_sub_object()` did before. That cleans up `_collect_sub_objects()`
 and allows `on_delete` behaviors to be added without touching any existing
 code (I added `on_delete=SET(value)`, because it's just a four line
 utility function).

  * Merged `CollectedFields` into `CollectedObjects`

  * Made all operations that require knowledge of internals methods on
 `CollectedObjects`. This makes `django.db.models.base.delete_objects` more
 readable.

  * Couldn't resist and rewrote parts of `CollectedObjects`.

--
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:29>
Django <http://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 post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Parent Message unknown Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:        
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by emulbreh):

 Changes between 7539.on_delete.r11706.diff and 7539.on_delete.r11724.diff:

  *  Updated to work with m2m-refactor
  *  Moved `delete_objects()` inside `CollectedObjects`:
 `CollectedObjects.delete()`
  *  Got rid of `DeleteQuery.delete_batch_related()`: use the normal code
 path for m2m intermediary models. This is required to enable `on_delete`
 for foreign keys on intermediary models. But it results in a dramatical
 increase of `SELECT` queries. Therefore ..
  *  Moved `_collect_sub_objects()` to `CollectedObjects` and changed its
 algorithm to collect related objects in batches. This reduces the number
 of `SELECT` queries for related objects. The delete call in the following
 example requires a total of 103 queries in trunk, while the patch only
 requires 4 queries: related `C` instances will be looked up in one bulk
 query.
     {{{
     #!python

     class A(models.Model): pass

     class B(models.Model):
      a = models.ForeignKey(A)

     class C(models.Model):
      b = models.ForeignKey(B)

     a = A.objects.create()
     for i in xrange(100): B.objects.create(a=a)
     a.delete()

     }}}
  *  Introduced a batch (don't select, just delete) option to get rid of
 the one remaining extra query for `auto_created` intermediary models.
  *  Altered `collect()` to collect inheritance parents without additional
 queries.
  *  Moved `CollectedObjects` into its own module, as it now encapsulates
 the whole deletion logic and depends on `db.models.sql`.


 TODO:
  * There is an ugly `contrib.contenttypes` import in `subqueries.py`.
 Deleting generic relations should be handled by a custom `on_delete`
 handler instead.

--
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:30>
Django <http://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 post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Parent Message unknown Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:        
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by emulbreh):

 Changes between 7539.on_delete.r11724.diff and
 7539.on_delete.r11724.2.diff:

  * Corrected the default behavior for nullable foreign keys (SET_NULL did
 not cause any test failures for those)
  * Moved `CASCADE`, `PROTECT`, `SET`, `SET_NULL`, `SET_DEFAULT`, and
 `DO_NOTHING` to `db.models.deletion`
  * Renamed `CollectedObjects` to `Collector`
  * Added a couple of docstrings
  * Moved sanity checks to `core.management.validation`

--
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:31>
Django <http://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 post to this group, send email to django-updates@...
To unsubscribe from this group, send email to django-updates+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Parent Message unknown Re: [Django] #7539: Add ON DELETE and ON UPDATE support to Django

by Django-3 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

#7539: Add ON DELETE and ON UPDATE support to Django
---------------------------------------------------+------------------------
          Reporter:  glassfordm                    |         Owner:        
            Status:  new                           |     Milestone:        
         Component:  Database layer (models, ORM)  |       Version:  SVN    
        Resolution:                                |      Keywords:  feature
             Stage:  Design decision needed        |     Has_patch:  1      
        Needs_docs:  1                             |   Needs_tests:  0      
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Changes (by edsu):

 * cc: ehs@... (added)

--
Ticket URL: <http://code.djangoproject.com/ticket/7539#comment:32>
Django <http://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 post to this group, send email to django-updates@....
For more options, visit this group at http://groups.google.com/group/django-updates?hl=.