Skip to content

Commit 439b24d

Browse files
committed
fix(LeanObject): test existence more accurately
Previously, the code checks whether the object has an truthy objectId, to determine the existence of a LeanCloud object. But if the object is constructed via `query.get("nonexist_objectId")`, then it does have an objectId (`{"objectId": "nonexist_objectId"}`). Therefore, we check whether the object has the `createdAt` attribute instead. Also update the comments of `is_new` and `is_existed`, to clarify their intented usage.
1 parent fea3240 commit 439b24d

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

leancloud/object_.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,21 @@ def is_new(self):
517517
"""
518518
判断当前对象是否已经保存至服务器。
519519
520+
该方法为 SDK 内部使用(save 调用此方法 dispatch 保存操作为 REST API 的 POST 和 PUT 请求)。
521+
查询对象是否在服务器上存在请使用 is_existed 方法。
522+
523+
520524
:rtype: bool
521525
"""
522526
return False if self.id else True
523527

524528
def is_existed(self):
525-
return bool(self.id)
529+
"""
530+
判断当前对象是否在服务器上已经存在。
531+
532+
:rtype: bool
533+
"""
534+
return self.has("createdAt")
526535

527536
def get_acl(self):
528537
"""

0 commit comments

Comments
 (0)