Skip to content

Commit

Permalink
Bugfix add timezone to compare 2 dates
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Jan 28, 2024
1 parent 91ec277 commit 5228ef3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/models/notion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from config.database import Base
from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy import Column, String, DateTime
from datetime import timezone


class Notion(Base):
Expand All @@ -8,4 +9,4 @@ class Notion(Base):
page_id = Column(String, primary_key=True)
content = Column(String, nullable=True)
embedded_at = Column(DateTime, nullable=True, default=None)
updated_at = Column(DateTime, nullable=True, default=None)
updated_at = Column(DateTime(timezone=True))
4 changes: 3 additions & 1 deletion app/routers/v1/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from services import notion as ns
from sqlalchemy.orm import Session
from schemas.notion import NotionCreateSchema, NotionUpdateSchema
from datetime import datetime, timezone


router = APIRouter(
Expand Down Expand Up @@ -64,8 +65,9 @@ def run_notion(db: Session = Depends(get_db)):
if page:
if ns.notion_object_exist(db, page_id=page.page_id):
existing_object = ns.get_notion_object_by_page_id(db, page_id=page.page_id)
existing_object_updated_at = existing_object.updated_at.replace(tzinfo=timezone.utc)

if existing_object.updated_at < page.updated_at:
if existing_object_updated_at < page.updated_at:
ns.update_notion_content(
session=db,
page_id=page.page_id,
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NotionSchema(BaseModel):
page_id: str
content: Optional[str] = None
embedded_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
updated_at: datetime


class NotionCreateSchema(BaseModel):
Expand Down

0 comments on commit 5228ef3

Please sign in to comment.