Skip to content

query.get(object_id) should throw an Exception when object not found #513

Open

Description

@weakish

This is consistent with query.first.

Thank artsungames for bringing this to our attention.

Activity

  1. Ma233 commented on Apr 14, 2021

    @Ma233

    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
  2. weakish commented on Apr 15, 2021

    @weakish
    ContributorAuthor

    可以通过 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    nextbreaking changes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions