#34907: loaddata crashes on objects with natural keys when don't exist on passed
database.
-------------------------------------+-------------------------------------
     Reporter:  Florian              |                    Owner:  AbId KhAn
         Type:  Bug                  |                   Status:  assigned
    Component:  Core                 |                  Version:  4.2
  (Serialization)                    |
     Severity:  Normal               |               Resolution:
     Keywords:  natural key, multi-  |             Triage Stage:  Accepted
  db, loaddata                       |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * component:  Database layer (models, ORM) => Core (Serialization)
 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the report.

 Django doesn't need to search for an object in the database when you don't
 use natural key, that's why it works.

 When natural keys are used Django tries to find a matching object in the
 database when building an instance based on JSON values. We could probably
 avoid this with:
 {{{#!diff
 diff --git a/django/core/serializers/python.py
 b/django/core/serializers/python.py
 index 7ec894aa00..47606aa248 100644
 --- a/django/core/serializers/python.py
 +++ b/django/core/serializers/python.py
 @@ -117,6 +117,8 @@ def Deserializer(
                  continue
              else:
                  raise
 +        if not router.allow_migrate_model(self.using, Model):
 +            continue
          data = {}
          if "pk" in d:
              try:
 }}}

 Does it work for you?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34907#comment:2>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018b4d10480c-93132bf3-8afb-47b9-bcd7-4a26c82a8fe6-000000%40eu-central-1.amazonses.com.

Reply via email to