Replace deprecated datetime.utcnow() with timezone-aware UTC
All checks were successful
Build And Test / publish (push) Successful in 48s
All checks were successful
Build And Test / publish (push) Successful in 48s
Use datetime.now(timezone.utc) instead of deprecated utcnow(). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
"""SQLModel database models for caching PIM data."""
|
"""SQLModel database models for caching PIM data."""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from sqlmodel import SQLModel, Field
|
from sqlmodel import SQLModel, Field
|
||||||
|
|
||||||
|
|
||||||
|
def utc_now() -> datetime:
|
||||||
|
"""Return timezone-aware UTC datetime."""
|
||||||
|
return datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
class CacheMeta(SQLModel, table=True):
|
class CacheMeta(SQLModel, table=True):
|
||||||
"""Generic key-value cache metadata."""
|
"""Generic key-value cache metadata."""
|
||||||
|
|
||||||
@@ -29,7 +34,7 @@ class EmailCache(SQLModel, table=True):
|
|||||||
is_flagged: bool = False
|
is_flagged: bool = False
|
||||||
snippet: Optional[str] = None
|
snippet: Optional[str] = None
|
||||||
full_data: Optional[str] = Field(default=None, description="JSON blob of full email data")
|
full_data: Optional[str] = Field(default=None, description="JSON blob of full email data")
|
||||||
cached_at: datetime = Field(default_factory=datetime.utcnow)
|
cached_at: datetime = Field(default_factory=utc_now)
|
||||||
|
|
||||||
|
|
||||||
class EventCache(SQLModel, table=True):
|
class EventCache(SQLModel, table=True):
|
||||||
@@ -43,7 +48,7 @@ class EventCache(SQLModel, table=True):
|
|||||||
start_time: Optional[datetime] = Field(default=None, index=True)
|
start_time: Optional[datetime] = Field(default=None, index=True)
|
||||||
end_time: Optional[datetime] = None
|
end_time: Optional[datetime] = None
|
||||||
full_data: Optional[str] = Field(default=None, description="JSON blob of full event data")
|
full_data: Optional[str] = Field(default=None, description="JSON blob of full event data")
|
||||||
cached_at: datetime = Field(default_factory=datetime.utcnow)
|
cached_at: datetime = Field(default_factory=utc_now)
|
||||||
|
|
||||||
|
|
||||||
class ContactCache(SQLModel, table=True):
|
class ContactCache(SQLModel, table=True):
|
||||||
@@ -56,7 +61,7 @@ class ContactCache(SQLModel, table=True):
|
|||||||
display_name: Optional[str] = Field(default=None, index=True)
|
display_name: Optional[str] = Field(default=None, index=True)
|
||||||
primary_email: Optional[str] = None
|
primary_email: Optional[str] = None
|
||||||
full_data: Optional[str] = Field(default=None, description="JSON blob of full contact data")
|
full_data: Optional[str] = Field(default=None, description="JSON blob of full contact data")
|
||||||
cached_at: datetime = Field(default_factory=datetime.utcnow)
|
cached_at: datetime = Field(default_factory=utc_now)
|
||||||
|
|
||||||
|
|
||||||
class SyncState(SQLModel, table=True):
|
class SyncState(SQLModel, table=True):
|
||||||
@@ -86,7 +91,7 @@ class SeenEmail(SQLModel, table=True):
|
|||||||
from_address: Optional[str] = Field(default=None, description="Sender email for logging")
|
from_address: Optional[str] = Field(default=None, description="Sender email for logging")
|
||||||
subject: Optional[str] = Field(default=None, description="Subject for logging")
|
subject: Optional[str] = Field(default=None, description="Subject for logging")
|
||||||
email_date: Optional[datetime] = Field(default=None, description="Email date")
|
email_date: Optional[datetime] = Field(default=None, description="Email date")
|
||||||
seen_at: datetime = Field(default_factory=datetime.utcnow)
|
seen_at: datetime = Field(default_factory=utc_now)
|
||||||
notification_sent: bool = Field(default=False)
|
notification_sent: bool = Field(default=False)
|
||||||
notification_sent_at: Optional[datetime] = None
|
notification_sent_at: Optional[datetime] = None
|
||||||
notification_error: Optional[str] = Field(
|
notification_error: Optional[str] = Field(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from imapclient import IMAPClient
|
from imapclient import IMAPClient
|
||||||
@@ -275,7 +275,7 @@ class EmailMonitor:
|
|||||||
) -> tuple[bool, Optional[str]]:
|
) -> tuple[bool, Optional[str]]:
|
||||||
"""Send webhook notification for a new email."""
|
"""Send webhook notification for a new email."""
|
||||||
payload = EmailNotificationPayload(
|
payload = EmailNotificationPayload(
|
||||||
timestamp=datetime.utcnow(),
|
timestamp=datetime.now(timezone.utc),
|
||||||
email_id=email.id,
|
email_id=email.id,
|
||||||
mailbox=mailbox,
|
mailbox=mailbox,
|
||||||
from_email=email.from_address.email,
|
from_email=email.from_address.email,
|
||||||
@@ -353,7 +353,7 @@ class EmailMonitor:
|
|||||||
subject=email.subject,
|
subject=email.subject,
|
||||||
email_date=email.date,
|
email_date=email.date,
|
||||||
notification_sent=notification_sent,
|
notification_sent=notification_sent,
|
||||||
notification_sent_at=datetime.utcnow() if notification_sent else None,
|
notification_sent_at=datetime.now(timezone.utc) if notification_sent else None,
|
||||||
)
|
)
|
||||||
session.add(seen)
|
session.add(seen)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
@@ -375,7 +375,7 @@ class EmailMonitor:
|
|||||||
seen = result.scalars().first()
|
seen = result.scalars().first()
|
||||||
if seen:
|
if seen:
|
||||||
seen.notification_sent = success
|
seen.notification_sent = success
|
||||||
seen.notification_sent_at = datetime.utcnow() if success else None
|
seen.notification_sent_at = datetime.now(timezone.utc) if success else None
|
||||||
seen.notification_error = error
|
seen.notification_error = error
|
||||||
session.add(seen)
|
session.add(seen)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user