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.get(object_id) should throw an Exception when object not found #513

Open
weakish opened this issue Apr 6, 2021 · 2 comments
Open
Labels
next breaking changes

Comments

@weakish
Copy link
Contributor

weakish commented Apr 6, 2021

This is consistent with query.first.

Thank artsungames for bringing this to our attention.

@weakish weakish added the next breaking changes label Apr 6, 2021
@Ma233
Copy link

Ma233 commented Apr 14, 2021

object_id 在云存储中不存在的时候,会返回一个本地构造的 object,可以通过 created_at 是否被设置来察觉到。
当前我们自己的项目里做了这样的 patch:

from leancloud import Query as OriginalQuery


class Query(OriginalQuery):
    def get(self, object_id):
        obj = super().get(object_id)

        # 此处也可以 raise 101,大家可以按自己的习惯来
        return obj if getattr(obj, "created_at", None) else None


def patch_leancloud():
    import leancloud

    leancloud.Query = Query

@weakish
Copy link
Contributor Author

weakish commented Apr 15, 2021

可以通过 crerated_at 是否被设置来察觉到

是的,其实 SDK 提供了一个 is_existed 方法(这个方法在实现上也是检查 created_at

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

No branches or pull requests

2 participants