Hi Dmitry,

The issue here isn't with the query, but with your code that's calling
it. Python is throwing an exception because your variable 'bus' that
you're trying to fetch checkpoint_id on is set to None, not because
the result of the query is None. The query code never gets run.

-Nick Johnson


On Apr 21, 12:56 pm, Dmitry Kachaev <dmitry.kach...@gmail.com> wrote:
> I use following construction to lookup records from datastore:
>
>             point_old=models.Checkpoint.all().filter("checkpoint_id
> =", bus.checkpoint_id).get()
>
> It works fine in most scenarios, but sometime I'm getting error like
> this:
>
> 'NoneType' object has no attribute 'checkpoint_id'
> Traceback (most recent call last):
>   File "/base/python_lib/versions/1/google/appengine/ext/webapp/
> __init__.py", line 501, in __call__
>     handler.get(*groups)
>   File "/base/data/home/apps/xxx/1.332943763447248076/tasks/
> busupdate.py", line 22, in get
>     self.update(bus)
>   File "/base/data/home/apps/xxx/1.332943763447248076/tasks/
> busupdate.py", line 45, in update
>     self.check_points(bus)
>   File "/base/data/home/apps/xxx/1.332943763447248076/tasks/
> busupdate.py", line 86, in check_points
>     logging.debug("found old checkpoint: %s" %
> (point_old.checkpoint_id))
> AttributeError: 'NoneType' object has no attribute 'checkpoint_id'
>
> Basically, get() returns None, but record I looked up is definitely in
> datastore.
>
> I figured out and replaced this look up call with equivalent GQL call:
>
>             point_old = db.GqlQuery("SELECT * FROM Checkpoint WHERE
> checkpoint_id = %s" % (bus.checkpoint_id)).get()
>             #point_old=models.Checkpoint.all().filter("checkpoint_id
> =", bus.checkpoint_id).get()
>
> What is wrong? Those constructs should behave the same way, but they
> don't. Commented one is not returning a record, when GQL is returning
> single record, just fine.
>
> Thanks,
> Dmitry
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to