Issue #16 resolved

Problem? working with django 1.5 (repo version)

jgsogo
created an issue

I happened to update my django to 1.5 version and I found a problem working with InheritanceManager and select_subclasses

== Where == An exception is raised in InheritanceQuerySet::iterator method at line 36: https://bitbucket.org/carljm/django-model-utils/src/3b66a0a41a61/model_utils/managers.py#cl-36 {{{

!python

def iterator(self): iter = super(InheritanceQuerySet, self).iterator() if getattr(self, 'subclasses', False): for obj in iter: sub_obj = [getattr(obj, s) for s in self.subclasses if getattr(obj, s)] or [obj] sub_obj = sub_obj[0] if getattr(self, '_annotated', False): for k in self._annotated: setattr(sub_obj, k, getattr(obj, k))

            yield sub_obj
    else:
        for obj in iter:
            yield obj

}}}

== What happens ==

When listing children it raises a "no exception supplied" exception,

{{{

!python

File "/home/javi/program/django_src/django/template/defaulttags.py" in render 145. len_values = len(values) File "/home/javi/program/django_src/django/db/models/query.py" in len 86. self._result_cache = list(self.iterator()) File "/home/javi/-----/django-apps/django-model-utils/model_utils/managers.py" in iterator 36. sub_obj = [getattr(obj, s) for s in self.subclasses if getattr(obj, s)] or [obj] File "/home/javi/program/django_src/django/db/models/fields/related.py" in get 271. raise self.related.model.DoesNotExist

Exception Type: DoesNotExist at / }}}

== Why (my opinion) ==

I think that this exception is caused by this changeset in django trunk: https://github.com/django/django/commit/b90d4e5b749be3b6caec8ece7729beb3876ea4b8 where the commiter modifies the behaviour of SingleRelatedObjectDescriptor::__get__ raising an exception where it was returned None.

== Solution ==

I'm not familiar with django neither with model-utils internals, so I would be able to suggest only an ugly patch (the one I'm applying right now to get rid of this), maybe someone come accross this issue and offers a better one.

... or maybe this is not an issue for model-utils but for django itself...

Comments (8)

  1. Log in to comment