Skip to content

Query 类的 or_ 方法和 and_ 方法中存在问题 #516

Description

@Ma233

参考代码 2.9.3 版本:https://github.com/leancloud/python-sdk/blob/v2.9.3/leancloud/query.py#L117

query = Query(queries[0]._query_class._class_name)
  1. 不应该使用 Query 声明新的对象,而应该使用 cls 来声明,否则会导致继承 Query 得来的 MyQuery 类的 or_ 方法和 and_ 方法返回父类声明的实例。
In [1]: from leancloud import Query

In [2]: class MyQuery(Query):
   ...:     pass
   ...:

In [3]: type(MyQuery('User').or_(MyQuery('User'), MyQuery('User')))
Out[3]: leancloud.query.Query
  1. 没有正确处理 ObjectMeta 中特殊处理过的 _ 开头的表。
In [1]: from leancloud import User

In [2]: User.query._query_class
Out[2]: leancloud.user.User

In [3]: User.query.or_(User.query, User.query)._query_class
Out[3]: leancloud.object_._User

Activity

  1. Ma233 commented on May 19, 2021

    @Ma233
    Author

    以上问题会给通过继承 Object 和 Query 来自定义功能带来困扰。

  2. weakish commented on May 20, 2021

    @weakish
    Contributor

    SDK 的设计当时没有考虑 Query 的子类化。(当然很欢迎提 PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions