django-nonrel/djangoappengine — Issue #14: Crash on inequality filters on primary key
Author: Wilfred
Created: 2012-01-11 17:17:19+00:00
State: open

This query is fine:

>>> Foo.objects.(id__gt=1)

This query crashes (as do negative IDs):

>>> Foo.objects.get(id__gt=0)

Traceback:

Traceback (most recent call last):
File "", line 1, in
File "/home/wilfred/work/gap2/django/db/models/query.py", line 70, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/home/wilfred/work/gap2/django/db/models/query.py", line 85, in __len__
self._result_cache.extend(self._iter)
File "/home/wilfred/work/gap2/django/db/models/query.py", line 276, in iterator
for row in compiler.results_iter():
File "/home/wilfred/work/gap2/djangotoolbox/db/basecompiler.py", line 229, in results_iter
for entity in self.build_query(fields).fetch(low_mark, high_mark):
File "/home/wilfred/work/gap2/djangotoolbox/db/basecompiler.py", line 289, in build_query
query.add_filters(self.query.where)
File "/home/wilfred/work/gap2/djangotoolbox/db/basecompiler.py", line 74, in add_filters
self.add_filters(child)
File "/home/wilfred/work/gap2/djangotoolbox/db/basecompiler.py", line 78, in add_filters
self.add_filter(column, lookup_type, self._negated, db_type, value)
File "/home/wilfred/work/gap2/djangoappengine/db/compiler.py", line 61, in _func
return func(*args, **kwargs)
File "/home/wilfred/work/gap2/djangoappengine/db/compiler.py", line 271, in add_filter
self._add_filter(column, op, db_type, value)
File "/home/wilfred/work/gap2/djangoappengine/db/compiler.py", line 294, in _add_filter
query[key] = value
File "/home/wilfred/bin/google_appengine-1.6.1/google/appengine/api/datastore.py", line 1667, in __setitem__
match = self._CheckFilter(filter, value)
File "/home/wilfred/bin/google_appengine-1.6.1/google/appengine/api/datastore.py", line 1806, in _CheckFilter
(datastore_types.KEY_SPECIAL_PROPERTY, value, typename(value)))
DatabaseError: invalid filter: __key__ filter value must be a Key; received None (a NoneType).

This query would have been useful to me (I was iterating over object in ID order using a task queue and I wanted my first iteration to start at zero). In any case, we ought to give a better error.