memius
memius

Reputation: 4125

Google Appengine: query object suddenly becomes list object without query attributes

I get this:

AttributeError: 'list' object has no attribute 'cursor'

on this line:

company_cursor = companies.cursor()

when running the following code:

q = Company.all()
q.order("datetime")
companies = q.fetch(5)

company_cursor = memcache.get("company_cursor")

if company_cursor:
    companies.with_cursor(start_cursor = company_cursor)

for company in companies: 
    do_stuff(company)

company_cursor = companies.cursor() 
memcache.set("company_cursor",company_cursor, 11000)

As far as I can see, my code looks like the example shown here:

https://developers.google.com/appengine/docs/python/datastore/queries.

Upvotes: 0

Views: 340

Answers (1)

Greg
Greg

Reputation: 10360

Your query is q, but fetch on a query returns a list of entities, so companies is in fact a list.

To have the cursor be part of the query, you need to add it before running fetch.

Upvotes: 1

Related Questions