Export to GitHub

google-app-engine-samples - issue #2

Bug in db.Query.filter - spaces cause silent query failure


Posted on Apr 13, 2008 by Helpful Giraffe

What steps will reproduce the problem? Look at this small code sample to query a simple entity in various ways.

from google.appengine.api import users from google.appengine.ext import db

class UserInterest(db.Model): user = db.UserProperty() interest = db.StringProperty()

me = users.get_current_user() interests = db.GqlQuery('SELECT * FROM UserInterest WHERE user = :1', me) #works interests = UserInterest.gql("WHERE user = :1", me) #works interests = UserInterest.all().filter("user = ", me) # works interests = UserInterest.all().filter("user =", me) # works interests = UserInterest.all().filter("user= ", me) # throws BadFilterError: BadFilterError: invalid filter: Could not parse filter string: user= . interests = UserInterest.all().filter("user=", me) # fails silently - just returns no rows!

What is the expected output? What do you see instead?

It appears that spaces are inadvertently significant in the construction of query filters, and the placing of them can cause filters to fail in highly unintuitive ways. For instance, the filters "x = " and "x =" work, but "x= " throws a BadFilterError, and "x=" silently fails by returning no rows.

Spaces should not be significant here. This bug could become a significant source of user frustration (it had me annoyed for a good couple of hours until i happened upon a working form after trying other forms of the query).

What version of the product are you using? On what operating system? release: "1.0" timestamp: 1206675800 Python 2.5.1 Linux

Please provide any additional information below.

Comment #1

Posted on Apr 13, 2008 by Helpful Giraffe

here is a patch to google/appengine/api/datastore.py that appears to fix the error, which lies in the FILTER_REGEX and the code that handles it.

Attachments

Comment #2

Posted on Apr 13, 2008 by Helpful Giraffe

Oops, sorry, meant to file this under google-app-engine, not samples. Please delete.

Comment #3

Posted on Dec 30, 2010 by Quick Kangaroo

dhimana malout

Attachments

Comment #4

Posted on Dec 30, 2010 by Quick Kangaroo

sandeep.

Comment #5

Posted on Feb 7, 2011 by Quick Wombat

Thanks you very much. Your post solved my problem.

Status: New

Labels:
Type-Defect Priority-Medium