Django

Code

Changeset 7163

Show
Ignore:
Timestamp:
02/26/08 18:44:44 (9 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Fixed #6664. Calling list() no longer swallows field errors.

This is slightly backwards incompatible with previous behaviour if you were
doing Tricky Stuff(tm) -- the exception type has changed if you try to create a
bad queryset.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/core/exceptions.py

    r6857 r7163  
    2828    "Django is somehow improperly configured" 
    2929    pass 
     30 
     31class FieldError(Exception): 
     32    """Some kind of problem with a model field.""" 
     33    pass 
     34 
  • django/branches/queryset-refactor/django/db/models/base.py

    r7142 r7163  
    77import django.db.models.manager 
    88from django.core import validators 
    9 from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned 
     9from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, FieldError 
    1010from django.db.models.fields import AutoField, ImageField, FieldDoesNotExist 
    1111from django.db.models.fields.related import OneToOneRel, ManyToOneRel, OneToOneField 
     
    102102                for field in base._meta.local_fields: 
    103103                    if field.name in names: 
    104                         raise TypeError('Local field %r in class %r clashes with field of similar name from abstract base class %r' 
     104                        raise FieldError('Local field %r in class %r clashes with field of similar name from abstract base class %r' 
    105105                                % (field.name, name, base.__name__)) 
    106106                    new_class.add_to_class(field.name, field) 
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r7162 r7163  
    2020from django.db.models.fields import FieldDoesNotExist, Field, related 
    2121from django.contrib.contenttypes import generic 
     22from django.core.exceptions import FieldError 
    2223from datastructures import EmptyResultSet 
    2324 
     
    549550            join_tuple = tuple([tuple(j) for j in joins]) 
    550551            if join_tuple in already_seen: 
    551                 raise TypeError('Infinite loop caused by ordering.') 
     552                raise FieldError('Infinite loop caused by ordering.') 
    552553            already_seen[join_tuple] = True 
    553554 
     
    736737        parts = arg.split(LOOKUP_SEP) 
    737738        if not parts: 
    738             raise TypeError("Cannot parse keyword query %r" % arg) 
     739            raise FieldError("Cannot parse keyword query %r" % arg) 
    739740 
    740741        # Work out the lookup type and remove it from 'parts', if necessary. 
     
    868869            except FieldDoesNotExist: 
    869870                names = opts.get_all_field_names() 
    870                 raise TypeError("Cannot resolve keyword %r into field. " 
     871                raise FieldError("Cannot resolve keyword %r into field. " 
    871872                        "Choices are: %s" % (name, ", ".join(names))) 
    872873            if model: 
     
    973974 
    974975        if pos != len(names) - 1: 
    975             raise TypeError("Join on field %r not permitted." % name) 
     976            raise FieldError("Join on field %r not permitted." % name) 
    976977 
    977978        return field, target, opts, joins 
     
    10341035                errors.append(item) 
    10351036        if errors: 
    1036             raise TypeError('Invalid order_by arguments: %s' % errors) 
     1037            raise FieldError('Invalid order_by arguments: %s' % errors) 
    10371038        if ordering: 
    10381039            self.order_by.extend(ordering) 
     
    12291230                    if self.alias_map[alias][ALIAS_REFCOUNT]: 
    12301231                        if table: 
    1231                             raise TypeError('Updates can only access a single database table at a time.') 
     1232                            raise FieldError('Updates can only access a single database table at a time.') 
    12321233                        table = alias 
    12331234        else: 
     
    12721273            if not direct or m2m: 
    12731274                # Can only update non-relation fields and foreign keys. 
    1274                 raise TypeError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field) 
     1275                raise fieldError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field) 
    12751276            if field.rel and isinstance(val, Model): 
    12761277                val = val.pk 
  • django/branches/queryset-refactor/tests/modeltests/custom_columns/models.py

    r6730 r7163  
    7272Traceback (most recent call last): 
    7373    ... 
    74 TypeError: Cannot resolve keyword 'firstname' into field. Choices are: article, first_name, id, last_name 
     74FieldError: Cannot resolve keyword 'firstname' into field. Choices are: article, first_name, id, last_name 
    7575 
    7676>>> a = Author.objects.get(last_name__exact='Smith') 
  • django/branches/queryset-refactor/tests/modeltests/field_subclassing/models.py

    r6753 r7163  
    66from django.utils.encoding import force_unicode 
    77from django.core import serializers 
     8from django.core.exceptions import FieldError 
    89 
    910class Small(object): 
     
    5152        if lookup_type == 'isnull': 
    5253            return [] 
    53         raise TypeError('Invalid lookup type: %r' % lookup_type) 
     54        raise FieldError('Invalid lookup type: %r' % lookup_type) 
    5455 
    5556    def flatten_data(self, follow, obj=None): 
     
    9596Traceback (most recent call last): 
    9697... 
    97 TypeError: Invalid lookup type: 'lt' 
     98FieldError: Invalid lookup type: 'lt' 
    9899 
    99100# Serialization works, too. 
  • django/branches/queryset-refactor/tests/modeltests/lookup/models.py

    r7149 r7163  
    271271Traceback (most recent call last): 
    272272    ... 
    273 TypeError: Cannot resolve keyword 'pub_date_year' into field. Choices are: headline, id, pub_date 
     273FieldError: Cannot resolve keyword 'pub_date_year' into field. Choices are: headline, id, pub_date 
    274274 
    275275>>> Article.objects.filter(headline__starts='Article') 
    276276Traceback (most recent call last): 
    277277    ... 
    278 TypeError: Join on field 'headline' not permitted. 
     278FieldError: Join on field 'headline' not permitted. 
    279279 
    280280# Create some articles with a bit more interesting headlines for testing field lookups: 
  • django/branches/queryset-refactor/tests/modeltests/many_to_one/models.py

    r6730 r7163  
    180180Traceback (most recent call last): 
    181181    ... 
    182 TypeError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
     182FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
    183183 
    184184# You need to specify a comparison clause 
     
    186186Traceback (most recent call last): 
    187187    ... 
    188 TypeError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
     188FieldError: Cannot resolve keyword 'reporter_id' into field. Choices are: headline, id, pub_date, reporter 
    189189 
    190190# You can also instantiate an Article by passing 
  • django/branches/queryset-refactor/tests/modeltests/model_inheritance/models.py

    r7143 r7163  
    149149Traceback (most recent call last): 
    150150    ... 
    151 TypeError: Cannot resolve keyword 'supplier' into field. Choices are: address, id, italianrestaurant, lot, name, place_ptr, provider, rating, serves_hot_dogs, serves_pizza 
     151FieldError: Cannot resolve keyword 'supplier' into field. Choices are: address, id, italianrestaurant, lot, name, place_ptr, provider, rating, serves_hot_dogs, serves_pizza 
    152152 
    153153# Parent fields can be used directly in filters on the child model. 
  • django/branches/queryset-refactor/tests/modeltests/reverse_lookup/models.py

    r6730 r7163  
    5656Traceback (most recent call last): 
    5757    ... 
    58 TypeError: Cannot resolve keyword 'choice' into field. Choices are: creator, id, poll_choice, question, related_choice 
     58FieldError: Cannot resolve keyword 'choice' into field. Choices are: creator, id, poll_choice, question, related_choice 
    5959"""} 
  • django/branches/queryset-refactor/tests/regressiontests/null_queries/models.py

    r6967 r7163  
    3838Traceback (most recent call last): 
    3939... 
    40 TypeError: Cannot resolve keyword 'foo' into field. Choices are: choice, id, poll 
     40FieldError: Cannot resolve keyword 'foo' into field. Choices are: choice, id, poll 
    4141 
    4242# Can't use None on anything other than __exact 
  • django/branches/queryset-refactor/tests/regressiontests/queries/models.py

    r7154 r7163  
    395395Traceback (most recent call last): 
    396396... 
    397 TypeError: Infinite loop caused by ordering. 
     397FieldError: Infinite loop caused by ordering. 
    398398 
    399399# If the remote model does not have a default ordering, we order by its 'id'