Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ma233 opened this issue May 19, 2021 · 2 comments
Open

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

Ma233 opened this issue May 19, 2021 · 2 comments
Assignees

Comments

@Ma233
Copy link

Ma233 commented May 19, 2021

参考代码 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
@Ma233
Copy link
Author

Ma233 commented May 19, 2021

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

@weakish
Copy link
Contributor

weakish commented May 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants