开发者

what is wrong in this query

I have a table something like

class BulkStore(PresageBaseModel):
    store_key = db.StringProperty(required=True)
    name = db.StringProperty(required=True)

But when I query on store_key it doesn't return anything

sk = 'agd2b3hhdWxhcjcLEhZwcmVzYWdlX2FwcF9jb2xsZWN0aW9uIhtwcmVzYWdlX2RlbW9fY29sbGVjdGlvbl9rZXkM'
print BulkStore.all().filter('store_key',sk).fetch(1)

output:

[]

but manual search gets the correct result

for bulkStore in BulkStore.all():
    if bulkStore.store_key == sk:
        print bulkStore

output:

BulkStore(key_id=849L, store_key开发者_JAVA技巧=u'agd2b3hhdWxhcjcLEhZwcmVzYWdlX2FwcF9jb2xsZWN0aW9uIhtwcmVzYWdlX2RlbW9fY29sbGVjdGlvbl9rZXkM', name=u'collection_record_export')

What i may be missing?


In one of your examples, the string ends with a ., in the other, it doesn't. These are not equal strings.


Reason for this bug is that if a property is assigned a value which is already another db type it mysteriously takes the type of that value, e.g. in my BulkStore model store_key is a StringProperty but if I assign it a value which is TextProperty, store_key is stored as TextProperty not StringProperty which I have defined it to be and later on query on such properties doesn't work, so in db you can have entities some of which will be searchable and some won't be.

so never do this

bulkstore.store_key = some_entity.some_text_value

instead do this

bulkstore.store_key = str(some_entity.some_text_value)

This can be a very subtle bug to find in code :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜