为什么调用get()时gql查询结果会导致异常
我试图用这个从我的数据存储中检索一个条目:
query = UserData.gql("WHERE mDeviceId = :1", id)
Utils.log("my Object:" + str(query))
entry = query.get()
碰巧变量“id”甚至不存在(打字错误),所以我知道如何解决这个问题,但我不明白为什么结果我get 不允许我对其调用 get() 。当我这样做时,我收到错误:
Exception: Unsupported type for property : <type 'builtin_function_or_method'>
通常我只是检查是否条目==无以查看是否没有结果。有谁知道为什么会发生这种情况,以及我是否应该以不同的方式对 None 进行检查,以防将来出现此类拼写错误?
I am attempting to retrieve an entry from my datastore with this:
query = UserData.gql("WHERE mDeviceId = :1", id)
Utils.log("my Object:" + str(query))
entry = query.get()
It just so happens that the variable 'id' doesn't even exist (typo), so I know how to fix this, but I don't understand why the result I get won't let me call get() on it. When I do, I get the error:
Exception: Unsupported type for property : <type 'builtin_function_or_method'>
Normally I just check if entry == None to see if I get no results. Does anyone know why this occurs and if I should be doing my checks for None differently, in case I have such typos in the future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
名为
id
的变量未在您的代码中定义,因此它传递了内置函数id
,并且 QL 抱怨它在需要值(整数?)时获取了一个函数。 。在使用之前请检查并确保为
id
分配了一个值。更好的是,不要用您自己的变量来隐藏内置函数——这会导致像这样的令人困惑的错误。 :-)
A variable named
id
is not defined in your code, so it passes the builtin functionid
, and QL complains that it's getting a function when it expected a value (integer?).Check to make sure you're assigning
id
a value before you use it.Even better, don't shadow builtins with your own variables-- it'll cause confusing errors like this. :-)