From 250281361d1341bd9b9481a16f16acc49a8f142a Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 25 Feb 2006 17:24:17 +0000 Subject: [PATCH] Changed get_object() not to use 'ordering' parameter from the model. Thanks, Ned Batchelder. Also updated some unit tests to show correct DoesNotExist output git-svn-id: http://code.djangoproject.com/svn/django/trunk@2392 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/meta/__init__.py | 1 + tests/testapp/models/basic.py | 2 +- tests/testapp/models/custom_pk.py | 2 +- tests/testapp/models/one_to_one.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 800975ef2a..af4e29167e 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -1352,6 +1352,7 @@ def _get_where_clause(lookup_type, table_prefix, field_name, value): raise TypeError, "Got invalid lookup_type: %s" % repr(lookup_type) def function_get_object(opts, klass, does_not_exist_exception, **kwargs): + kwargs['order_by'] = kwargs.get('order_by', ()) obj_list = function_get_list(opts, klass, **kwargs) if len(obj_list) < 1: raise does_not_exist_exception, "%s does not exist for %s" % (opts.object_name, kwargs) diff --git a/tests/testapp/models/basic.py b/tests/testapp/models/basic.py index dc108011e0..6ce64322e4 100644 --- a/tests/testapp/models/basic.py +++ b/tests/testapp/models/basic.py @@ -67,7 +67,7 @@ datetime.datetime(2005, 7, 28, 0, 0) >>> articles.get_object(id__exact=2) Traceback (most recent call last): ... -ArticleDoesNotExist: Article does not exist for {'id__exact': 2} +ArticleDoesNotExist: Article does not exist for {'order_by': (), 'id__exact': 2} >>> articles.get_object(pub_date__year=2005, pub_date__month=8) Traceback (most recent call last): diff --git a/tests/testapp/models/custom_pk.py b/tests/testapp/models/custom_pk.py index 5b0eb45462..24041d64cd 100644 --- a/tests/testapp/models/custom_pk.py +++ b/tests/testapp/models/custom_pk.py @@ -45,7 +45,7 @@ Fran Bones >>> employees.get_object(pk='foo') Traceback (most recent call last): ... -EmployeeDoesNotExist: Employee does not exist for {'pk': 'foo'} +EmployeeDoesNotExist: Employee does not exist for {'pk': 'foo', 'order_by': ()} # Fran got married and changed her last name. >>> fran = employees.get_object(pk='XYZ456') diff --git a/tests/testapp/models/one_to_one.py b/tests/testapp/models/one_to_one.py index b8f68836b3..b5d749c25d 100644 --- a/tests/testapp/models/one_to_one.py +++ b/tests/testapp/models/one_to_one.py @@ -53,7 +53,7 @@ Demon Dogs the restaurant >>> p2.get_restaurant() Traceback (most recent call last): ... -RestaurantDoesNotExist: Restaurant does not exist for {'place__id__exact': ...} +RestaurantDoesNotExist: Restaurant does not exist for {'order_by': (), 'place__id__exact': ...} # restaurants.get_list() just returns the Restaurants, not the Places. >>> restaurants.get_list()