Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.5.x]Merge pull request #494 from mrj0/model_split

model_split: Fixed #19236 - fixed error for abstract models with a split method

Backport of 8d3f932
  • Loading branch information...
commit 69a0c91c90a3c8f8d5913874aca918aecbe69410 1 parent 3bb8c6e
Alex Gaynor authored November 04, 2012 Alex Gaynor committed November 04, 2012
18  django/db/models/fields/related.py
@@ -54,14 +54,16 @@ class MyModel(Model):
17  tests/regressiontests/m2m_regress/models.py
@@ -61,3 +61,20 @@ class Worksheet(models.Model):
61 61
 class User(models.Model):
62 62
     name = models.CharField(max_length=30)
63 63
     friends = models.ManyToManyField(auth.User)
  64
+
  65
+
  66
+class BadModelWithSplit(models.Model):
  67
+    name = models.CharField(max_length=1)
  68
+
  69
+    def split(self):
  70
+        raise RuntimeError('split should not be called')
  71
+
  72
+    class Meta:
  73
+        abstract = True
  74
+
  75
+
  76
+class RegressionModelSplit(BadModelWithSplit):
  77
+    """
  78
+    Model with a split method should not cause an error in add_lazy_relation
  79
+    """
  80
+    others = models.ManyToManyField('self')
8  tests/regressiontests/m2m_regress/tests.py
@@ -5,7 +5,7 @@
5 5
 from django.utils import six
6 6
 
7 7
 from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild,
8  
-    SelfReferChildSibling, Worksheet)
  8
+    SelfReferChildSibling, Worksheet, RegressionModelSplit)
9 9
 
10 10
 
11 11
 class M2MRegressionTests(TestCase):
@@ -90,3 +90,9 @@ def test_manager_class_caching(self):
90 90
         # Get same manager for different instances
91 91
         self.assertTrue(e1.topics.__class__ is e2.topics.__class__)
92 92
         self.assertTrue(t1.entry_set.__class__ is t2.entry_set.__class__)
  93
+
  94
+    def test_m2m_abstract_split(self):
  95
+        # Regression for #19236 - an abstract class with a 'split' method
  96
+        # causes a TypeError in add_lazy_relation
  97
+        m1 = RegressionModelSplit(name='1')
  98
+        m1.save()

0 notes on commit 69a0c91

Please sign in to comment.
Something went wrong with that request. Please try again.