Ver Fonte

Ignore and log errors in ThreadItem deserialization

Tulir Asokan há 4 anos atrás
pai
commit
7f1e9a2895

+ 14 - 2
mauigpapi/types/thread_item.py

@@ -13,16 +13,20 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
-from typing import List, Optional, Union, Any
+from typing import List, Optional, Union
+import logging
 
 import attr
 from attr import dataclass
-from mautrix.types import SerializableAttrs, SerializableEnum, JSON
+from mautrix.types import SerializableAttrs, SerializableEnum, JSON, SerializerError, Obj
 from mautrix.types.util.serializable_attrs import _dict_to_attrs
 
 from .account import BaseResponseUser, UserIdentifier
 
 
+log = logging.getLogger("mauigpapi.types")
+
+
 class ThreadItemType(SerializableEnum):
     DELETION = "deletion"
     MEDIA = "media"
@@ -421,3 +425,11 @@ class ThreadItem(SerializableAttrs['ThreadItem']):
     reactions: Optional[Reactions] = None
     like: Optional[str] = None
     link: Optional[LinkItem] = None
+
+    @classmethod
+    def deserialize(cls, data: JSON) -> Union['ThreadItem', Obj]:
+        try:
+            return _dict_to_attrs(cls, data)
+        except SerializerError:
+            log.debug("Failed to deserialize ThreadItem %s", data)
+            return Obj(**data)

+ 2 - 0
mautrix_instagram/example-config.yaml

@@ -204,6 +204,8 @@ logging:
     loggers:
         mau:
             level: DEBUG
+        mauigpapi:
+            level: DEBUG
         aiohttp:
             level: INFO
         paho.mqtt:

+ 1 - 1
mautrix_instagram/portal.py

@@ -429,7 +429,7 @@ class Portal(DBPortal, BasePortal):
             self.log.trace("Item content: %s", item.serialize())
 
     async def _handle_instagram_item(self, source: 'u.User', sender: 'p.Puppet', item: ThreadItem,
-                                    is_backfill: bool = False) -> None:
+                                     is_backfill: bool = False) -> None:
         if item.client_context in self._reqid_dedup:
             self.log.debug(f"Ignoring message {item.item_id} by {item.user_id}"
                            " as it was sent by us (client_context in dedup queue)")