#22421: Loading fixtures with one-to-one inheritance and M2M with natural keys fails since 1.7 Beta -------------------------------------+------------------------------------- Reporter: stanislas.guerra@… | Owner: nobody Type: Bug | Status: new Component: Core | Version: master (Serialization) | Resolution: Severity: Normal | Triage Stage: Keywords: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by stanislas.guerra@…):
* needs_better_patch: => 0 * needs_docs: => 0 * needs_tests: => 0 Comment: Looks like it came from this commit in ''django/db/models/fields/related.py#ForeignObject.get_instance_value_for_fields(instance, fields)'' : https://github.com/django/django/commit/244e2b71f512605f3d0a8e1ba4c9d6b538acf69d#diff-301 Which is related to the ticket #20820 {{{ - ret.append(instance.pk) - else: - ret.append(getattr(instance, field.attname)) + possible_parent_link = opts.get_ancestor_link(field.model) + if not possible_parent_link or possible_parent_link.primary_key: + ret.append(instance.pk) + continue + ret.append(getattr(instance, field.attname)) return tuple(ret) }}} And especially the last line: `ret.append(getattr(instance, field.attname))` (`<assistant obj>.id` in that case) which add a `None` to the returned Tuple raising an Exception in `create_many_related_manager()` : {{{ self.related_val = source_field.get_foreign_related_value(instance) if None in self.related_val: raise ValueError('"%r" needs to have a value for field "%s" before ' 'this many-to-many relationship can be used.' % (instance, source_field_name)) }}} Because the Assistant object has not been saved yet. FYI, the fixture loading fails when trying to save the ''Assistant'' object (which is a one-to-one to ''User'') because of the M2M ''user_permissions'' relation. Hope this helps. -- Ticket URL: <https://code.djangoproject.com/ticket/22421#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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/084.eedf12b68d4fc1b02111203bdba24e1b%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.