Fix AttributeError with matrix-nio 0.11+
This commit is contained in:
parent
8b8829af86
commit
4bae3cf90e
|
@ -3,7 +3,7 @@
|
||||||
"""`ModelItem` subclasses definitions."""
|
"""`ModelItem` subclasses definitions."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
||||||
|
@ -224,7 +224,12 @@ class Event(ModelItem):
|
||||||
|
|
||||||
def serialize_field(self, field: str) -> Any:
|
def serialize_field(self, field: str) -> Any:
|
||||||
if field == "source":
|
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 json.dumps(source_dict)
|
||||||
|
|
||||||
return super().serialize_field(field)
|
return super().serialize_field(field)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user