Sukhdeep
Sukhdeep

Reputation: 168

Google App Engine fetch() ValueError: need more than 1 value to unpack

gql_query = "SELECT * FROM Dev_DB"
searchquery = ndb.gql(gql_query)

BATCH_SIZE = 1
results, cursor, more = searchquery.fetch(BATCH_SIZE)

Execution of the above code is resulting in ValueError: need more than 1 value to unpack.

The error is getting solved when I'm giving BATCH_SIZE value as 3 instead of 1. But still, it then fetches only first row of data instead of all 3.

The whole function for reference:

def update_pose_order_db_controller(self):
    self.response.headers['Content-type']="text/html"
    self.response.out.write("<p>Hello there, Fetching from dev</p>")

    cursor_from_url = self.request.get('start_cursor')
    logging.info("Cursor in start is: {}".format(cursor_from_url))

    gql_query = "SELECT * FROM Dev_DB"
    searchquery = ndb.gql(gql_query)

    if cursor_from_url:
        cursor_from_url = Cursor(urlsafe=cursor_from_url)
        BATCH_SIZE = 2
        results, cursor, more = searchquery.fetch(BATCH_SIZE, start_cursor = cursor_from_url)
    else:
        BATCH_SIZE = 1
        results, cursor, more = searchquery.fetch(BATCH_SIZE)

    self.response.write(results.ans_list)

The problem occurs in the else part because, at the start, the cursor is empty. Any value for BATCH_SIZE >= 3 works. The code never went to if part because the initial fetching is not getting successful and hence the cursor is not getting set to the URL as a parameter.

I'm new to the Google App Engine. Any help is appreciated.

Upvotes: 0

Views: 44

Answers (1)

Sukhdeep
Sukhdeep

Reputation: 168

I was using fetch() instead of fetch_page(). fetch is for DB and fetch_page() is for NDB.

Upvotes: 1

Related Questions