mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-08 11:56:59 +00:00
Replace remaining datetime.utcnow() call sites in session CRUD, incognito purge cutoff, and webhook payloads with core.database.utcnow_naive.
This commit is contained in:
+10
-10
@@ -162,7 +162,7 @@ def _persist_session_headers(session_id: str, headers: dict | None) -> None:
|
|||||||
db_session = db.query(DbSession).filter(DbSession.id == session_id).first()
|
db_session = db.query(DbSession).filter(DbSession.id == session_id).first()
|
||||||
if db_session:
|
if db_session:
|
||||||
db_session.headers = headers or {}
|
db_session.headers = headers or {}
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception:
|
except Exception:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
@@ -223,8 +223,8 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
# purge exists only to catch ghosts the frontend missed (tab close,
|
# purge exists only to catch ghosts the frontend missed (tab close,
|
||||||
# crash). Only clean up rows old enough to be definitely orphaned.
|
# crash). Only clean up rows old enough to be definitely orphaned.
|
||||||
try:
|
try:
|
||||||
from datetime import datetime as _dt, timedelta as _td
|
from datetime import timedelta as _td
|
||||||
_cutoff = _dt.utcnow() - _td(minutes=10)
|
_cutoff = utcnow_naive() - _td(minutes=10)
|
||||||
_purge_db = SessionLocal()
|
_purge_db = SessionLocal()
|
||||||
try:
|
try:
|
||||||
from core.database import ChatMessage as _DbMsg
|
from core.database import ChatMessage as _DbMsg
|
||||||
@@ -470,7 +470,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
db_session = db.query(DbSession).filter(DbSession.id == sid).first()
|
db_session = db.query(DbSession).filter(DbSession.id == sid).first()
|
||||||
if db_session:
|
if db_session:
|
||||||
db_session.folder = folder if folder else None
|
db_session.folder = folder if folder else None
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
result["folder"] = folder if folder else None
|
result["folder"] = folder if folder else None
|
||||||
finally:
|
finally:
|
||||||
@@ -517,7 +517,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
db_session.model = model
|
db_session.model = model
|
||||||
db_session.endpoint_url = endpoint_url
|
db_session.endpoint_url = endpoint_url
|
||||||
db_session.headers = session.headers or {}
|
db_session.headers = session.headers or {}
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
@@ -646,7 +646,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
db_session = db.query(DbSession).filter(DbSession.id == sid).first()
|
db_session = db.query(DbSession).filter(DbSession.id == sid).first()
|
||||||
if db_session:
|
if db_session:
|
||||||
db_session.archived = True
|
db_session.archived = True
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Update in memory if it exists
|
# Update in memory if it exists
|
||||||
@@ -680,7 +680,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
if not db_session:
|
if not db_session:
|
||||||
raise HTTPException(404, f"Session {sid} not found")
|
raise HTTPException(404, f"Session {sid} not found")
|
||||||
db_session.archived = False
|
db_session.archived = False
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
# Reload into session manager so it appears in the active list
|
# Reload into session manager so it appears in the active list
|
||||||
try:
|
try:
|
||||||
@@ -890,7 +890,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
db_session = db.query(DbSession).filter(DbSession.id == session_id).first()
|
db_session = db.query(DbSession).filter(DbSession.id == session_id).first()
|
||||||
if db_session:
|
if db_session:
|
||||||
db_session.is_important = important
|
db_session.is_important = important
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Update in memory if it exists
|
# Update in memory if it exists
|
||||||
@@ -979,7 +979,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
metadata={
|
metadata={
|
||||||
"compacted": True,
|
"compacted": True,
|
||||||
"summarized_count": len(older),
|
"summarized_count": len(older),
|
||||||
"timestamp": datetime.utcnow().isoformat(),
|
"timestamp": utcnow_naive().isoformat(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
new_history = [summary_msg] + recent
|
new_history = [summary_msg] + recent
|
||||||
@@ -1256,7 +1256,7 @@ def setup_session_routes(session_manager: SessionManager, config: dict, webhook_
|
|||||||
db_session = db_session_q.first()
|
db_session = db_session_q.first()
|
||||||
if db_session:
|
if db_session:
|
||||||
db_session.folder = folder_name
|
db_session.folder = folder_name
|
||||||
db_session.updated_at = datetime.utcnow()
|
db_session.updated_at = utcnow_naive()
|
||||||
updated += 1
|
updated += 1
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
"""Regression: session routes must not call datetime.utcnow() (#1116)."""
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
import routes.session_routes as sr
|
||||||
|
|
||||||
|
|
||||||
|
def test_session_routes_module_does_not_reference_utcnow():
|
||||||
|
source = inspect.getsource(sr)
|
||||||
|
assert "datetime.utcnow()" not in source
|
||||||
|
assert "_dt.utcnow()" not in source
|
||||||
Reference in New Issue
Block a user