From 4bae3cf90e49c75d4bf986c235780a4faee9c744 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 14 May 2020 13:58:34 -0400 Subject: [PATCH] Fix AttributeError with matrix-nio 0.11+ --- src/backend/models/items.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/models/items.py b/src/backend/models/items.py index 11b31156..2c7c1a05 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -3,7 +3,7 @@ """`ModelItem` subclasses definitions.""" import json -from dataclasses import dataclass, field +from dataclasses import asdict, dataclass, field from datetime import datetime, timedelta from pathlib import Path from typing import Any, Dict, List, Optional, Tuple, Type, Union @@ -224,7 +224,12 @@ class Event(ModelItem): def serialize_field(self, field: str) -> Any: if field == "source": - source_dict = nio.attr.asdict(self.source) if self.source else {} + try: + as_dict = nio.attr.asdict # nio < 0.11 + except AttributeError: + as_dict = asdict + + source_dict = as_dict(self.source) if self.source else {} return json.dumps(source_dict) return super().serialize_field(field)