﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9981	getting objects where column is null throws exception, when you define ordering by that column	antje.gaida@…	Malcolm Tredinnick	"i have the following class defined:
{{{
#!python
class Foo(models.Model):
    bar = models.ForeignKey(Bar, null=True, blank=True)
    name = models.CharField(max_length=100, null=True, blank=True)
    
    class Meta:
        ordering = ['bar', 'name']
}}}

now trying to get an object throws this exception, unless you don't delete 'bar' from ordering:
{{{
>>> f = Foo(name=""asdf"")
>>> f.save()
>>> f.id
38500L
>>> f2 = Foo.objects.get(id=38500)
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/tools/python/lib/python2.5/site-packages/django/db/models/manager.py"", line 93, in get
    return self.get_query_set().get(*args, **kwargs)
  File ""/tools/python/lib/python2.5/site-packages/django/db/models/query.py"", line 309, in get
    % self.model._meta.object_name)
DoesNotExist: Foo matching query does not exist.
}}}
is there already a bugfix? of course there is a workaround here with order_by but you can search a very long time until you find it

thank you,

antje"		closed	Database layer (models, ORM)	dev		worksforme	foreign keys, null, get		Unreviewed	0	0	0	0	0	0
