hitrust / google-app-engine-samples

Automatically exported from code.google.com/p/google-app-engine-samples
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by benha...@gmail.com on 13 Apr 2008 at 5:53

GoogleCodeExporter commented 8 years ago
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.

Original comment by benha...@gmail.com on 13 Apr 2008 at 6:22

Attachments:

GoogleCodeExporter commented 8 years ago
Oops, sorry, meant to file this under google-app-engine, not samples. Please 
delete.

Original comment by benha...@gmail.com on 13 Apr 2008 at 6:33

GoogleCodeExporter commented 8 years ago
dhimana malout

Original comment by sandeepd...@gmail.com on 30 Dec 2010 at 11:46

Attachments:

GoogleCodeExporter commented 8 years ago
sandeep.

Original comment by sandeepd...@gmail.com on 30 Dec 2010 at 11:56

GoogleCodeExporter commented 8 years ago
Thanks you very much. Your post solved my problem.

Original comment by handarus...@gmail.com on 7 Feb 2011 at 4:10