From cb342c07e859667cf41cccfedc8682769972f6ef Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 19 Mar 2021 18:17:59 +0100 Subject: [PATCH] [Models] Fixed optional detection --- flaschengeist/models/__init__.py | 6 ++---- flaschengeist/plugins/schedule/models.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/flaschengeist/models/__init__.py b/flaschengeist/models/__init__.py index c7b94d1..27431a0 100644 --- a/flaschengeist/models/__init__.py +++ b/flaschengeist/models/__init__.py @@ -14,10 +14,8 @@ class ModelSerializeMixin: return False import typing - - if typing.get_origin(self.__class__.__annotations__[param]) is typing.Union and typing.get_args( - self.__class__.__annotations__[param] - )[1] is type(None): + hint = typing.get_type_hints(self.__class__)[param] + if typing.get_origin(hint) is typing.Union and len(typing.get_args(hint)) == 2 and typing.get_args(hint)[1] is type(None): return getattr(self, param) is None def serialize(self): diff --git a/flaschengeist/plugins/schedule/models.py b/flaschengeist/plugins/schedule/models.py index 04c060f..228ed0d 100644 --- a/flaschengeist/plugins/schedule/models.py +++ b/flaschengeist/plugins/schedule/models.py @@ -80,7 +80,7 @@ class Event(db.Model, ModelSerializeMixin): id: int = db.Column(db.Integer, primary_key=True) start: datetime = db.Column(UtcDateTime, nullable=False) - end: datetime = db.Column(UtcDateTime) + end: Optional[datetime] = db.Column(UtcDateTime) description: Optional[str] = db.Column(db.String(255)) type: EventType = db.relationship("EventType") jobs: list[Job] = db.relationship(