我有一个使用 python 在 Google App Engine 上运行的应用程序。 模型类扩展自 ndb (google.appengine.ext.ndb) 类。
我的一个 View 对数据库进行异步调用,或多或少类似于:
# ExerciseListLog is a ndb model class
# start_current, end_current are dates
# student_id is a string
# contents is a list of keys
exercise_log_query = ExerciseListLog.query(ndb.AND(ExerciseListLog.creation >= start_current,
ExerciseListLog.creation < end_current,
ExerciseListLog.user_id == student_id))
exercise_log_query = exercise_log_query.filter(ExerciseListLog.content.IN(contents))
future = exercise_log_query.count_async()
count = future.get_result() # this throws BadQueryError
这会在 get_result() 上引发错误: BadQueryError:无法将 FalseNode 转换为谓词
但只有当我将代码部署到 Google 云时才会发生这种情况。当我在本地运行它时,它工作正常。
我不知道这个错误是什么意思,在 Google 上查找它也没有多大帮助。 有人知道这里出了什么问题吗?
这是来自 GAE 日志的完整堆栈跟踪
Traceback (most recent call last):
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/zen/web/gae/convention.py", line 48, in make_convention
method(*args, **kwargs)
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/core/web/qmhandler.py", line 48, in wrapper
return method(self, *args, **kwargs)
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/core/user/login/security.py", line 36, in wrapper
method(self, *args, **kwargs)
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/core/user/security.py", line 17, in wrapper
method(self, *args_inner, **kwargs)
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/plugins/web/desempenho/estatisticas.py", line 127, in class_activities
school_class.content)
File "/base/data/home/apps/s~qmagtest/1.366092357976105290/plugins/web/desempenho/estatisticas.py", line 178, in _get_exercise_video_and_total_weekly_series
exercise_log_count = exercise_count_futures[i].get_result()
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 325, in get_result
self.check_success()
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/tasklets.py", line 371, in _help_tasklet_along
value = gen.send(val)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 1227, in _count_async
dsquery = self._get_query(conn)
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 873, in _get_query
filters = filters._to_filter()
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 599, in _to_filter
for node in self.__nodes
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 600, in <genexpr>
if isinstance(node, PostFilterNode) == post))
File "/python27_runtime/python27_lib/versions/1/google/appengine/ext/ndb/query.py", line 425, in _to_filter
'Cannot convert FalseNode to predicate')
BadQueryError: Cannot convert FalseNode to predicate
最佳答案
我怀疑问题是内容是一个空列表。这几乎是 FalseNode 可能出现的唯一原因。 (另一个是不带参数调用 AND()。)您观察到删除此行证实了我的预感。您可能没想到会发生这种情况,并且在您的本地测试中它从未发生过……您可能需要调试该列表中的代码。
我同意错误消息可能会更好。
关于python - 使用 ndb 的 GAE 错误 - BadQueryError : Cannot convert FalseNode to predicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15531450/