File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 """
Original file line number Diff line number Diff line change @@ -237,7 +237,9 @@ def test_fetch(): # type: () -> None
237237 album .save ()
238238
239239 album_1 = Album .create_without_data (album .id )
240+ assert album_1 .is_existed () is False
240241 album_1 .fetch (include = ['parent' ], select = ['name' , 'parent' ])
242+ assert album_1 .is_existed () is True
241243 assert album_1 .get ('parent' ).get ('name' ) == 'Nightwish'
242244 assert not album_1 .has ('title' )
243245
@@ -252,6 +254,11 @@ def test_has(): # type: () -> None
252254 assert album .has ('bar' ) is False
253255
254256
257+ def test_existence (): # type: () -> None
258+ album = Album ()
259+ assert album .is_existed () is False
260+
261+
255262def test_get_set_acl (): # type: () -> None
256263 acl = leancloud .ACL ()
257264 album = Album ()
Original file line number Diff line number Diff line change @@ -169,6 +169,9 @@ def test_basic_query(): # type: () -> None
169169 # get
170170 GameScore .query .get (game_score .id )
171171
172+ # get nonexist
173+ assert GameScore .query .get ("NonexistentID" ).is_existed () is False
174+
172175 # count
173176 eq_ (GameScore .query .count (), 10 )
174177
You can’t perform that action at this time.
0 commit comments