From 67a58801623cccd55ecdd7d21f7b2dc487175c03 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 31 Mar 2009 21:42:47 +0000 Subject: [1.0.X] Fixed #10413: RelatedManager.add no longer fails silenty when trying to add an object of the wrong type. Thanks, dgouldin. Backport of r10226 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10293 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/many_to_many/models.py | 6 ++++++ tests/modeltests/many_to_one/models.py | 7 +++++++ 2 files changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py index cc34c868b9..21b4e82aa0 100644 --- a/tests/modeltests/many_to_many/models.py +++ b/tests/modeltests/many_to_many/models.py @@ -61,6 +61,12 @@ ValueError: 'Article' instance needs to have a primary key value before a many-t # Adding a second time is OK >>> a2.publications.add(p3) +# Adding an object of the wrong type raises TypeError +>>> a2.publications.add(a1) +Traceback (most recent call last): +... +TypeError: 'Publication' instance expected + # Add a Publication directly via publications.add by using keyword arguments. >>> new_publication = a2.publications.create(title='Highlights for Children') diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index 1972ac72ee..8093e73013 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -72,6 +72,13 @@ __test__ = {'API_TESTS':""" >>> r2.article_set.add(new_article2) >>> new_article2.reporter.id 2 + +# Adding an object of the wrong type raises TypeError +>>> r.article_set.add(r2) +Traceback (most recent call last): +... +TypeError: 'Article' instance expected + >>> r.article_set.all() [, ] >>> r2.article_set.all() -- cgit v1.3