Loading django/db/models/fields/related.py +10 −8 Original line number Diff line number Diff line Loading @@ -54,14 +54,16 @@ def add_lazy_relation(cls, field, relation, operation): else: # Look for an "app.Model" relation if isinstance(relation, six.string_types): try: app_label, model_name = relation.split(".") except ValueError: # If we can't split, assume a model in current app app_label = cls._meta.app_label model_name = relation except AttributeError: # If it doesn't have a split it's actually a model class else: # it's actually a model class app_label = relation._meta.app_label model_name = relation._meta.object_name Loading tests/regressiontests/m2m_regress/models.py +17 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,20 @@ class Worksheet(models.Model): class User(models.Model): name = models.CharField(max_length=30) friends = models.ManyToManyField(auth.User) class BadModelWithSplit(models.Model): name = models.CharField(max_length=1) def split(self): raise RuntimeError('split should not be called') class Meta: abstract = True class RegressionModelSplit(BadModelWithSplit): """ Model with a split method should not cause an error in add_lazy_relation """ others = models.ManyToManyField('self') tests/regressiontests/m2m_regress/tests.py +7 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ from django.test import TestCase from django.utils import six from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild, SelfReferChildSibling, Worksheet) SelfReferChildSibling, Worksheet, RegressionModelSplit) class M2MRegressionTests(TestCase): Loading Loading @@ -90,3 +90,9 @@ class M2MRegressionTests(TestCase): # Get same manager for different instances self.assertTrue(e1.topics.__class__ is e2.topics.__class__) self.assertTrue(t1.entry_set.__class__ is t2.entry_set.__class__) def test_m2m_abstract_split(self): # Regression for #19236 - an abstract class with a 'split' method # causes a TypeError in add_lazy_relation m1 = RegressionModelSplit(name='1') m1.save() Loading
django/db/models/fields/related.py +10 −8 Original line number Diff line number Diff line Loading @@ -54,14 +54,16 @@ def add_lazy_relation(cls, field, relation, operation): else: # Look for an "app.Model" relation if isinstance(relation, six.string_types): try: app_label, model_name = relation.split(".") except ValueError: # If we can't split, assume a model in current app app_label = cls._meta.app_label model_name = relation except AttributeError: # If it doesn't have a split it's actually a model class else: # it's actually a model class app_label = relation._meta.app_label model_name = relation._meta.object_name Loading
tests/regressiontests/m2m_regress/models.py +17 −0 Original line number Diff line number Diff line Loading @@ -61,3 +61,20 @@ class Worksheet(models.Model): class User(models.Model): name = models.CharField(max_length=30) friends = models.ManyToManyField(auth.User) class BadModelWithSplit(models.Model): name = models.CharField(max_length=1) def split(self): raise RuntimeError('split should not be called') class Meta: abstract = True class RegressionModelSplit(BadModelWithSplit): """ Model with a split method should not cause an error in add_lazy_relation """ others = models.ManyToManyField('self')
tests/regressiontests/m2m_regress/tests.py +7 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ from django.test import TestCase from django.utils import six from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild, SelfReferChildSibling, Worksheet) SelfReferChildSibling, Worksheet, RegressionModelSplit) class M2MRegressionTests(TestCase): Loading Loading @@ -90,3 +90,9 @@ class M2MRegressionTests(TestCase): # Get same manager for different instances self.assertTrue(e1.topics.__class__ is e2.topics.__class__) self.assertTrue(t1.entry_set.__class__ is t2.entry_set.__class__) def test_m2m_abstract_split(self): # Regression for #19236 - an abstract class with a 'split' method # causes a TypeError in add_lazy_relation m1 = RegressionModelSplit(name='1') m1.save()