user1769203
user1769203

Reputation: 349

google app engine - datastore filtering not retrieving as expected

Doing gql.query and not getting any results when I KNOW from looking at the datastore that there is a matching entry -- anyone ? maybe it has to do with the format of my variables?

for each in leveloneAdd:
    new = tuple(each[1:-1].split(','))
    tag = new[0]
    htype = new[1]

    q1 = Level_1_Headings.all().filter("name1 =",tag).filter("heading_type =",htype).get()

So in my logs: have confirmed that values of variables are as follows:

INFO     2013-01-14 20:28:38,370 main.py:293] new is (u"'english'", u" 'subject'")
INFO     2013-01-14 20:28:38,370 main.py:295] tag is 'english'
INFO     2013-01-14 20:28:38,370 main.py:297] heading type is  'subject'

Also have confirmed that entry does exit (both name1 and heading_type are indexable)

Upvotes: 1

Views: 90

Answers (1)

RocketDonkey
RocketDonkey

Reputation: 37249

Looking at your tuple, you appear to have strings that contain quotes:

(u"'english'", u" 'subject'")

Therefore when you try to query them, you are querying 'english' instead of english, which I'm assuming you want. Try stripping out the quotes from your original string if possible to see if the result returns as expected. You can see the difference here:

In [61]: t = (u"'english'", u"'subject'")

In [62]: a, b = t

In [63]: print a, b
'english' 'subject'

In [64]: t = (u"english", u"subject")

In [65]: a, b = t

In [66]: print a, b
english subject

To fix it, you could try something like this (note: you have a leading space in front of subject, so you may need to adjust for that):

In [68]: a, b = [i.strip("'") for i in t]

In [69]: a, b
Out[69]: (u'english', u'subject')

In [70]: print a, b
english subject

Upvotes: 2

Related Questions