python - 在 Google 应用引擎中按 'order' 对结果进行排序导致错误

标签 python google-app-engine

我在 GAE 模型中有一个属性,它是 DATETIME 类型。当我尝试按此属性对查询结果进行排序时,出现以下错误:

类型错误:issubclass() arg 1 必须是一个类

这是我的查询:

data_query = db.Query(docket).filter('last_update_date >', date).order('-last_update_date')

最佳答案

db.Query 期望提供一个 class 作为其第一个参数(或 model_class 关键字参数)。

class Query (model_class=None, ...)
    model_class
        Model (or Expando) class representing the entity kind
        to which the query applies.

Source

当我向 提供 db.Model 派生类(实体)的实例时,我成功重现了您的问题db.Query。尝试将 docket 替换为类或 docket.__class__

db.Query.order方法尝试测试model_class是否是db.Expando的子类时,会发生异常。由于它使用了issubclass的内置Python函数,它要求其参数是一个类。过滤之所以有效,是因为 db.Query.filter 不会尝试确定您的模型是否扩展 db.Expando

关于python - 在 Google 应用引擎中按 'order' 对结果进行排序导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17609020/

相关文章:

google-app-engine - 在 grails install-plugin app-engine 期间,Google App Engine 上的 Grails 部署被 Unresolved 依赖项阻止

java - Google App Engine - 云调试器是否可用?

python - 确定掷骰子是否包含某些组合?

python - 如何将一个图的输出作为 tensorflow 中另一图的输入传递

python - 无法使用 BeautifulSoup 在直接级别中提取文本

java - 如何在 Google App Engine 中停止 Jetty 网络服务器

python - 将 gethostbyaddr 与应用程序引擎结合使用

java - 有人获得了 .jar 来在谷歌应用程序引擎上运行吗?

python - sqlalchemy : filter by relationship (like django orm)?

python - 用QWebEngineView显示html时如何获取verticalScrollBar的最大值和当前值