Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: Use SQLAlchemy-UTC for proper timezone handling with SQLite

LearningCircuit7c2f40cd4461
diff --git a/pdm.lock b/pdm.lock
index 48dbc1bcfc..964381d270 100644
--- a/pdm.lock
+++ b/pdm.lock
@@ -5,7 +5,7 @@
groups = ["default", "dev"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
-content_hash = "sha256:ad9bfc3e522432da1261240f7864e9e6ddb0e9b5c6b346749e33b31cc15f88ae"
+content_hash = "sha256:88a559f826c10bf50dd6ef3fb737d447901134cd0bb1edfc82636c6983c3ab82"
[[metadata.targets]]
requires_python = ">=3.10"
@@ -5246,6 +5246,20 @@ files = [
{file = "sqlalchemy-2.0.41.tar.gz", hash = "sha256:edba70118c4be3c2b1f90754d308d0b79c6fe2c0fdc52d8ddf603916f83f4db9"},
]
+[[package]]
+name = "sqlalchemy-utc"
+version = "0.14.0"
+summary = "SQLAlchemy type to store aware datetime values"
+groups = ["default"]
+dependencies = [
+ "SQLAlchemy>=0.9.0",
+ "setuptools",
+]
+files = [
+ {file = "SQLAlchemy-Utc-0.14.0.tar.gz", hash = "sha256:8e041624595b66d7b1d5ea8b6de486df5c1b9352697f3b24f862f0ded56cd7aa"},
+ {file = "SQLAlchemy_Utc-0.14.0-py2.py3-none-any.whl", hash = "sha256:d2379eed5cce372128b5e744ce382decd262b2c742ab31f7f22ca11c6647f60b"},
+]
+
[[package]]
name = "sqlcipher3"
version = "0.5.4"
diff --git a/pyproject.toml b/pyproject.toml
index 56fb015d26..3551698c85 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -36,6 +36,7 @@ dependencies = [
"flask-cors>=3.0.10",
"flask-socketio>=5.1.1",
"sqlalchemy>=1.4.23",
+ "sqlalchemy-utc>=0.14.0",
"wikipedia",
"arxiv>=1.4.3",
"pypdf",
diff --git a/scripts/pre_commit/check_datetime_timezone.py b/scripts/pre_commit/check_datetime_timezone.py
index da35452aa8..21aad9bea6 100755
--- a/scripts/pre_commit/check_datetime_timezone.py
+++ b/scripts/pre_commit/check_datetime_timezone.py
@@ -1,16 +1,17 @@
#!/usr/bin/env python3
-"""Pre-commit hook to check that all DateTime columns in SQLAlchemy models have timezone=True."""
+"""Pre-commit hook to ensure all datetime columns use UtcDateTime for SQLite compatibility."""
import ast
+import re
import sys
from pathlib import Path
from typing import List, Tuple
-def check_datetime_columns(file_path: Path) -> List[Tuple[int, str]]:
- """Check a Python file for DateTime columns without timezone=True.
+def check_datetime_columns(file_path: Path) -> List[Tuple[int, str, str]]:
+ """Check a Python file for DateTime columns that should use UtcDateTime.
- Returns a list of (line_number, line_content) tuples for violations.
+ Returns a list of (line_number, line_content, error_message) tuples for violations.
"""
violations = []
@@ -22,6 +23,12 @@ def check_datetime_columns(file_path: Path) -> List[Tuple[int, str]]:
print(f"Error reading {file_path}: {e}", file=sys.stderr)
return violations
+ # Check if file imports UtcDateTime (if it uses any DateTime columns)
+ has_utc_datetime_import = (
+ "from sqlalchemy_utc import UtcDateTime" in content
+ or "from sqlalchemy_utc import utcnow, UtcDateTime" in content
+ )
+
# Parse the AST to find Column definitions with DateTime
try:
tree = ast.parse(content)
@@ -40,21 +47,54 @@ def check_datetime_columns(file_path: Path) -> List[Tuple[int, str]]:
isinstance(datetime_call.func, ast.Name)
and datetime_call.func.id == "DateTime"
):
- # Check if timezone=True is present
- has_timezone = False
- for keyword in datetime_call.keywords:
- if keyword.arg == "timezone":
- has_timezone = True
- break
-
- if not has_timezone:
- # Find the line number
+ # This should be UtcDateTime instead
+ line_num = node.lineno
+ if 0 <= line_num - 1 < len(lines):
+ violations.append(
+ (
+ line_num,
+ lines[line_num - 1].strip(),
+ "Use UtcDateTime instead of DateTime for SQLite compatibility",
+ )
+ )
+ elif (
+ isinstance(datetime_call.func, ast.Name)
+ and datetime_call.func.id == "UtcDateTime"
+ ):
+ # This is correct, but check if import exists
+ if not has_utc_datetime_import:
line_num = node.lineno
if 0 <= line_num - 1 < len(lines):
violations.append(
- (line_num, lines[line_num - 1].strip())
+ (
+ line_num,
+ lines[line_num - 1].strip(),
+ "Missing import: from sqlalchemy_utc import UtcDateTime",
+ )
)
+ # Also check for func.now() usage which should be utcnow()
+ for i, line in enumerate(lines, 1):
+ if "func.now()" in line and "Column" in line:
+ violations.append(
+ (
+ i,
+ line.strip(),
+ "Use utcnow() instead of func.now() for timezone-aware defaults",
+ )
+ )
+ # Check for datetime.utcnow or datetime.now(UTC) in defaults
+ if re.search(
+ r"default\s*=\s*(lambda:\s*)?datetime\.(utcnow|now)", line
+ ):
+ violations.append(
+ (
+ i,
+ line.strip(),
+ "Use utcnow() from sqlalchemy_utc instead of datetime functions for defaults",
+ )
+ )
+
return violations
@@ -80,13 +120,18 @@ def main():
all_violations.append((file_path, violations))
if all_violations:
- print("\n❌ DateTime columns without timezone=True found:\n")
+ print("\n❌ DateTime column issues found:\n")
for file_path, violations in all_violations:
print(f" {file_path}:")
- for line_num, line_content in violations:
- print(f" Line {line_num}: {line_content}")
- print("\n Fix: Add timezone=True to all DateTime columns")
- print(" Example: Column(DateTime(timezone=True), ...)\n")
+ for line_num, line_content, error_msg in violations:
+ print(f" Line {line_num}: {error_msg}")
+ print(f" > {line_content}")
+ print(
+ "\n Fix: Use UtcDateTime from sqlalchemy_utc for all datetime columns"
+ )
+ print(" Example: ")
+ print(" from sqlalchemy_utc import UtcDateTime, utcnow")
+ print(" Column(UtcDateTime, default=utcnow(), ...)\n")
return 1
return 0
diff --git a/src/local_deep_research/database/models/benchmark.py b/src/local_deep_research/database/models/benchmark.py
index c3058ea0ab..077851887a 100644
--- a/src/local_deep_research/database/models/benchmark.py
+++ b/src/local_deep_research/database/models/benchmark.py
@@ -6,7 +6,6 @@ from sqlalchemy import (
JSON,
Boolean,
Column,
- DateTime,
Enum,
Float,
ForeignKey,
@@ -16,10 +15,8 @@ from sqlalchemy import (
Text,
UniqueConstraint,
)
-
-# Removed duplicate import - declarative_base not needed here
from sqlalchemy.orm import relationship
-from sqlalchemy.sql import func
+from sqlalchemy_utc import UtcDateTime, utcnow
# Use the same base as the main app
from . import Base
@@ -73,17 +70,12 @@ class BenchmarkRun(Base):
status = Column(
Enum(BenchmarkStatus), default=BenchmarkStatus.PENDING, nullable=False
)
- created_at = Column(
- DateTime(timezone=True), server_default=func.now(), nullable=False
- )
+ created_at = Column(UtcDateTime, default=utcnow(), nullable=False)
updated_at = Column(
- DateTime(timezone=True),
- server_default=func.now(),
- onupdate=func.now(),
- nullable=False,
+ UtcDateTime, default=utcnow(), onupdate=utcnow(), nullable=False
)
- start_time = Column(DateTime(timezone=True), nullable=True)
- end_time = Column(DateTime(timezone=True), nullable=True)
+ start_time = Column(UtcDateTime, nullable=True)
+ end_time = Column(UtcDateTime, nullable=True)
# Progress tracking
total_examples = Column(Integer, default=0, nullable=False)
@@ -161,10 +153,8 @@ class BenchmarkResult(Base):
grader_response = Column(Text, nullable=True)
# Timestamps
- created_at = Column(
- DateTime(timezone=True), server_default=func.now(), nullable=False
- )
- completed_at = Column(DateTime(timezone=True), nullable=True)
+ created_at = Column(UtcDateTime, default=utcnow(), nullable=False)
+ completed_at = Column(UtcDateTime, nullable=True)
# Error handling
research_error = Column(Text, nullable=True)
@@ -211,21 +201,16 @@ class BenchmarkConfig(Base):
datasets_config = Column(JSON, nullable=False)
# Metadata
- created_at = Column(
- DateTime(timezone=True), server_default=func.now(), nullable=False
- )
+ created_at = Column(UtcDateTime, default=utcnow(), nullable=False)
updated_at = Column(
- DateTime(timezone=True),
- server_default=func.now(),
- onupdate=func.now(),
- nullable=False,
+ UtcDateTime, default=utcnow(), onupdate=utcnow(), nullable=False
)
is_default = Column(Boolean, default=False, nullable=False)
is_public = Column(Boolean, default=True, nullable=False)
# Usage tracking
usage_count = Column(Integer, default=0, nullable=False)
- last_used = Column(DateTime(timezone=True), nullable=True)
+ last_used = Column(UtcDateTime, nullable=True)
# Performance data (if available)
best_accuracy = Column(Float, nullable=True)
@@ -256,9 +241,7 @@ class BenchmarkProgress(Base):
)
# Progress data
- timestamp = Column(
- DateTime(timezone=True), server_default=func.now(), nullable=False
- )
+ timestamp = Column(UtcDateTime, default=utcnow(), nullable=False)
completed_examples = Column(Integer, nullable=False)
total_examples = Column(Integer, nullable=False)
@@ -268,7 +251,7 @@ class BenchmarkProgress(Base):
# Performance metrics
processing_rate = Column(Float, nullable=True) # Examples per minute
- estimated_completion = Column(DateTime(timezone=True), nullable=True)
+ estimated_completion = Column(UtcDateTime, nullable=True)
# Current status
current_dataset = Column(Enum(DatasetType), nullable=True)