Skip to content

Commit

Permalink
added missing datetime replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson committed Oct 3, 2024
1 parent 3d3da5f commit 71bb287
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions mealie/db/models/group/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from pydantic import ConfigDict
from sqlalchemy import ForeignKey, orm
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql.sqltypes import Boolean, DateTime, String
from sqlalchemy.sql.sqltypes import Boolean, String

from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase

from .._model_utils.auto_init import auto_init
from .._model_utils.datetime import get_utc_now
from .._model_utils.datetime import NaiveDateTime, get_utc_now
from .._model_utils.guid import GUID

if TYPE_CHECKING:
Expand All @@ -23,7 +23,7 @@ class ReportEntryModel(SqlAlchemyBase, BaseMixins):
success: Mapped[bool | None] = mapped_column(Boolean, default=False)
message: Mapped[str] = mapped_column(String, nullable=True)
exception: Mapped[str] = mapped_column(String, nullable=True)
timestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=get_utc_now)
timestamp: Mapped[datetime] = mapped_column(NaiveDateTime, nullable=False, default=get_utc_now)

report_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("group_reports.id"), nullable=False, index=True)
report: Mapped["ReportModel"] = orm.relationship("ReportModel", back_populates="entries")
Expand All @@ -40,7 +40,7 @@ class ReportModel(SqlAlchemyBase, BaseMixins):
name: Mapped[str] = mapped_column(String, nullable=False)
status: Mapped[str] = mapped_column(String, nullable=False)
category: Mapped[str] = mapped_column(String, index=True, nullable=False)
timestamp: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=get_utc_now)
timestamp: Mapped[datetime] = mapped_column(NaiveDateTime, nullable=False, default=get_utc_now)

entries: Mapped[list[ReportEntryModel]] = orm.relationship(
ReportEntryModel, back_populates="report", cascade="all, delete-orphan"
Expand Down
3 changes: 2 additions & 1 deletion mealie/schema/response/query_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sqlalchemy.sql import sqltypes

from mealie.db.models._model_base import SqlAlchemyBase
from mealie.db.models._model_utils.datetime import NaiveDateTime
from mealie.db.models._model_utils.guid import GUID

Model = TypeVar("Model", bound=SqlAlchemyBase)
Expand Down Expand Up @@ -177,7 +178,7 @@ def validate(self, model_attr_type: Any) -> Any:
except ValueError as e:
raise ValueError(f"invalid query string: invalid UUID '{v}'") from e

if isinstance(model_attr_type, sqltypes.Date | sqltypes.DateTime):
if isinstance(model_attr_type, sqltypes.Date | sqltypes.DateTime | NaiveDateTime):
try:
dt = date_parser.parse(v)
sanitized_values[i] = dt.date() if isinstance(model_attr_type, sqltypes.Date) else dt
Expand Down

0 comments on commit 71bb287

Please sign in to comment.