sajingeo / rietveld

Automatically exported from code.google.com/p/rietveld
Apache License 2.0
0 stars 0 forks source link

models.py r427:line602 filter argument incorrect #134

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
-    return cls.all().filter('lower_nickname =', nickname.lower()).get()
+    return cls.all().filter(lower_nickname=nickname.lower()).get()

Original issue reported on code.google.com by lihaitao on 23 Jul 2009 at 10:29

Attachments:

GoogleCodeExporter commented 9 years ago
Have you tested this? It seems you're thinking Django query syntax. But this is 
App
Engine.

Original comment by gvanrossum@gmail.com on 24 Jul 2009 at 1:51

GoogleCodeExporter commented 9 years ago
The current query is ok. The proposed change is Django's query syntax and 
doesn't work on App Engine 
(filter() got an unexpected keyword argument 'lower_nickname').

But while having a look at this I encountered an unexpected behavior of the 
filter() function. If there's no 
whitespace between the property name and the equal sign, the equal sign is 
treated as part of the property 
name.
In google.appengine.ext.db there is a regex _FILTER_REGEX that allows this. 
Here's a stripped down example:

>>> r = re.compile('^\s*([^\s]+)(\s+(%s)\s*)?$' % ('=|<='))
>>> r.match('foo=').groups()
('foo=', None, None)
>>> r.match('foo =').groups()
('foo', ' =', '=')

I had expected that either the query would work or that some kind of error is 
raised as it should be pretty 
unusual that a property name or any other value that may occur at this point 
ends with a equal sign. Or is 
the query without the whitespace just a programming error as the GQL grammar 
defines a whitespaces between 
property and operator?
At least a bit confusing because a GqlQuery allows it:

>>> from google.appengine.ext import db
>>> from codereview import models
>>> query = db.GqlQuery("SELECT * FROM Account WHERE lower_nickname='test'")
>>> print query.count()
1
>>> query = models.Account.all().filter('lower_nickname=', 'test')
>>> print query.count()
0

Original comment by albrecht.andi on 24 Jul 2009 at 6:05

GoogleCodeExporter commented 9 years ago
I am running Rietveld with gea2django without App Engine.

But if change the code a little bit, it could work on my environment, and 
hopefully
on App Engine. (I haven't tested on App Engine).

  @classmethod
  def get_account_for_nickname(cls, nickname):
     """Get the list of Accounts that have this nickname."""
     assert nickname
     assert '@' not in nickname
-    return cls.all().filter('lower_nickname =', nickname.lower()).get()
+    accounts = cls.all()
+    accounts.filter("lower_nickname = ", nickname.lower())
+    return accounts.get()

Test:
>>> accounts = codereview.models.Account.all()
>>> accounts.filter("lower_nickname = ", u'nname')
>>> accounts.get()
<Account: Account object>
>>> codereview.models.Account.all().filter("lower_nickname = ",  u'nname').get()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'get'

Original comment by lihaitao on 24 Jul 2009 at 8:03

GoogleCodeExporter commented 9 years ago
Please report bugs regarding gae2django (or Rietveld with gae2django) on it's 
project 
page (http://code.google.com/p/django-gae2django/issues/list).
Rietveld (this project) is a pure App Engine application.

Original comment by albrecht.andi on 24 Jul 2009 at 8:08