Ticket #14948: django-1.2-router_related_accessor-2.patch
File django-1.2-router_related_accessor-2.patch, 3.8 KB (added by , 14 years ago) |
---|
-
django/db/models/base.py
612 612 613 613 for related in self._meta.get_all_related_many_to_many_objects(): 614 614 if related.field.rel.through: 615 db = router.db_for_write(related.field.rel.through .__class__, instance=self)615 db = router.db_for_write(related.field.rel.through, instance=self) 616 616 opts = related.field.rel.through._meta 617 617 reverse_field_name = related.field.m2m_reverse_field_name() 618 618 nullable = opts.get_field(reverse_field_name).null … … 622 622 623 623 for f in self._meta.many_to_many: 624 624 if f.rel.through: 625 db = router.db_for_write(f.rel.through .__class__, instance=self)625 db = router.db_for_write(f.rel.through, instance=self) 626 626 opts = f.rel.through._meta 627 627 field_name = f.m2m_field_name() 628 628 nullable = opts.get_field(field_name).null -
tests/regressiontests/multiple_database/tests.py
1698 1698 def tearDown(self): 1699 1699 router.routers = self.old_routers 1700 1700 1701 def test_attribute_error (self):1701 def test_attribute_error_read(self): 1702 1702 "Check that the AttributeError from AttributeErrorRouter bubbles up" 1703 router.routers = [] 1704 b = Book.objects.create(title="Pro Django", 1705 published=datetime.date(2008, 12, 16)) 1706 router.routers = [AttributeErrorRouter()] 1707 self.assertRaises(AttributeError, Book.objects.get, pk=b.pk) 1708 1709 def test_attribute_error_save(self): 1710 "Check that the AttributeError from AttributeErrorRouter bubbles up" 1703 1711 dive = Book() 1704 1712 dive.title="Dive into Python" 1705 1713 dive.published = datetime.date(2009, 5, 4) 1706 1714 self.assertRaises(AttributeError, dive.save) 1707 1715 1716 def test_attribute_error_delete(self): 1717 "Check that the AttributeError from AttributeErrorRouter bubbles up" 1718 router.routers = [] 1719 b = Book.objects.create(title="Pro Django", 1720 published=datetime.date(2008, 12, 16)) 1721 p = Person.objects.create(name="Marty Alchin") 1722 b.authors = [p] 1723 b.editor = p 1724 router.routers = [AttributeErrorRouter()] 1725 self.assertRaises(AttributeError, b.delete) 1726 1727 def test_attribute_error_m2m(self): 1728 "Check that the AttributeError from AttributeErrorRouter bubbles up" 1729 router.routers = [] 1730 b = Book.objects.create(title="Pro Django", 1731 published=datetime.date(2008, 12, 16)) 1732 p = Person.objects.create(name="Marty Alchin") 1733 router.routers = [AttributeErrorRouter()] 1734 self.assertRaises(AttributeError, setattr, b, 'authors', [p]) 1735 1708 1736 class ModelMetaRouter(object): 1709 1737 "A router to ensure model arguments are real model classes" 1710 1738 def db_for_write(self, model, **hints): 1711 1739 if not hasattr(model, '_meta'): 1712 1740 raise ValueError 1713 1741 1714 class Router M2MThroughTestCase(TestCase):1742 class RouterThroughTestCase(TestCase): 1715 1743 multi_db = True 1716 1744 1717 1745 def setUp(self): … … 1732 1760 b.authors.remove(p) 1733 1761 # test clear 1734 1762 b.authors.clear() 1763 # test setattr 1764 b.authors = [p] 1765 # test _collect_sub_objects 1766 b.delete() 1767 1768 def test_fk_through(self): 1769 person = Person.objects.create(name='Bob') 1770 pet = Pet.objects.create(owner=person, name='Wart') 1771 # test _collect_sub_objects 1772 person.delete()