diff --git a/changelog b/changelog index bcbd263..086a1d0 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,14 @@ +## [2.9.9] - 2021-12-14 + +### Added + +- LCFile exposes the `key` attribute for non-external files. + +### Fixed + +- created_at and updated_at were missing on LCFile. +- updated_at was missing on new created LCObject. + ## [2.9.8] - 2021-12-10 ### Fixed diff --git a/docs/_modules/leancloud/file_.html b/docs/_modules/leancloud/file_.html index a204d96..c5a55f3 100644 --- a/docs/_modules/leancloud/file_.html +++ b/docs/_modules/leancloud/file_.html @@ -102,6 +102,8 @@

leancloud.file_ 源代码

         self._name = name
         self.key = None
         self.id = None
+        self.created_at = None
+        self.updated_at = None
         self._url = None
         self._successful_url = None
         self._acl = None
@@ -293,9 +295,18 @@ 

leancloud.file_ 源代码

         }
         response = client.post("/files".format(self._name), data)
         content = response.json()
+
         self.id = content["objectId"]
+
         self._successful_url = self._url
 
+        _created_at = utils.decode_date_string(content.get("createdAt"))
+        _updated_at = utils.decode_updated_at(content.get("updatedAt"), _created_at)
+        if _created_at is not None:
+            self.created_at = _created_at
+        if _updated_at is not None:
+            self.updated_at = _updated_at
+
     def _save_to_qcloud(self, token, upload_url):
         headers = {
             "Authorization": token,
@@ -356,10 +367,19 @@ 

leancloud.file_ 源代码

         if "url" in server_data:
             self._url = server_data.get("url")
             self._successful_url = self._url
+        if "key" in server_data:
+            self.key = server_data.get("key")
         if "mime_type" in server_data:
             self._mime_type = server_data["mime_type"]
         if "metaData" in server_data:
             self._metadata = server_data.get("metaData")
+        
+        _created_at = utils.decode_date_string(server_data.get("createdAt"))
+        _updated_at = utils.decode_updated_at(server_data.get("updatedAt"), _created_at)
+        if _created_at is not None:
+            self.created_at = _created_at
+        if _updated_at is not None:
+            self.updated_at = _updated_at
 
     def _get_file_token(self):
         data = {
diff --git a/docs/_modules/leancloud/object_.html b/docs/_modules/leancloud/object_.html
index 2b6c736..68d635b 100644
--- a/docs/_modules/leancloud/object_.html
+++ b/docs/_modules/leancloud/object_.html
@@ -401,25 +401,18 @@ 

leancloud.object_ 源代码

         }
 
     def _merge_metadata(self, server_data):
-        for key in ("objectId", "createdAt", "updatedAt"):
-            if server_data.get(key) is None:
-                continue
-            if key == "objectId":
-                self.id = server_data[key]
-            else:
-                if isinstance(server_data[key], six.string_types):
-                    dt = utils.decode(key, {"__type": "Date", "iso": server_data[key]})
-                elif server_data[key]["__type"] == "Date":
-                    dt = utils.decode(key, server_data[key])
-                else:
-                    raise TypeError("Invalid date type")
-                server_data[key] = dt
-                if key == "createdAt":
-                    self.created_at = dt
-                elif key == "updatedAt":
-                    self.updated_at = dt
-                else:
-                    raise TypeError
+        object_id = server_data.get("objectId")
+        _created_at = utils.decode_date_string(server_data.get("createdAt"))
+        _updated_at = utils.decode_updated_at(server_data.get("updatedAt"), _created_at)
+
+        if object_id is not None:
+            self.id = object_id
+        if _created_at is not None:
+            self.created_at = _created_at
+        if _updated_at is not None:
+            self.updated_at = _updated_at
+
+
 
 
[文档] def validate(self, attrs): if "ACL" in attrs and not isinstance(attrs["ACL"], leancloud.ACL): @@ -437,6 +430,23 @@

leancloud.object_ 源代码

         # for backward compatibility
         if (deafult is not None) and (default is None):
             default = deafult
+
+        # createdAt is stored as string in the cloud but used as datetime object on the client side.
+        # We need to make sure that `.created_at` and `.get("createdAt")` return the same value.
+        # Otherwise users will get confused.
+        if attr == "createdAt":
+            if self.created_at is None:
+                return None
+            else:
+                return self.created_at
+
+        # Similar to createdAt.
+        if attr == "updatedAt":
+            if self.updated_at is None:
+                return None
+            else:
+                return self.updated_at
+        
         return self._attributes.get(attr, default)
[文档] def relation(self, attr): diff --git a/setup.py b/setup.py index 4c7ac6b..337e219 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ setup( name='leancloud', - version='2.9.8', + version='2.9.9', description='LeanCloud Python SDK', url='https://leancloud.cn/', author='asaka',