~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
docs: clarify that utcnow() parentheses are required in Column defaults (#3244)
LearningCircuit04ae68ca585c
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 27d6affdaa..70abcd7fa8 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -213,6 +213,14 @@ repos:language: scriptfiles: \.(py|json)$description: "Ensure module_path values use relative imports, not absolute paths"+ - id: check-utcnow-parens+ name: Check utcnow() has parentheses in Column defaults+ entry: .pre-commit-hooks/check-utcnow-parens.py+ language: script+ files: \.py$+ exclude: ^(\.pre-commit-hooks/|tests/)+ description: "Prevent default=utcnow (missing parens) — utcnow is a FunctionElement+ class, parens are required to create the SQL expression object"- id: check-pdm-lockname: Check pdm.lock syncentry: .pre-commit-hooks/check-pdm-lock.shdiff --git a/.pre-commit-hooks/check-utcnow-parens.py b/.pre-commit-hooks/check-utcnow-parens.pynew file mode 100755index 0000000000..f5f6e27bc4--- /dev/null+++ b/.pre-commit-hooks/check-utcnow-parens.py@@ -0,0 +1,55 @@+#!/usr/bin/env python3+"""+Pre-commit hook to prevent removing parentheses from utcnow() in SQLAlchemy+Column defaults.++utcnow (from sqlalchemy_utc) is a FunctionElement *class*, not a plain+Python function. ``default=utcnow()`` creates a SQL expression object that+SQLAlchemy renders inline per-INSERT (e.g. CURRENT_TIMESTAMP). Passing the+bare class ``default=utcnow`` causes SQLAlchemy to call it as a Python+callable and then try to bind the resulting FunctionElement as a parameter+value, raising TypeError at insert time.++Correct: default=utcnow() onupdate=utcnow() server_default=utcnow()+Wrong: default=utcnow[no parens] onupdate=utcnow[no parens]+"""++import re+import sys++# Match default=utcnow or onupdate=utcnow NOT followed by (+# This catches: default=utcnow, default=utcnow) default=utcnow\n+_BAD_PATTERN = re.compile(r"\b(default|onupdate)\s*=\s*utcnow\s*(?=[,\)\s\n])")+++def main() -> int:+ exit_code = 0+ for filepath in sys.argv[1:]:+ try:+ with open(filepath, encoding="utf-8") as f:+ lines = f.readlines()+ except Exception:+ continue++ for i, line in enumerate(lines, 1):+ if _BAD_PATTERN.search(line):+ print(+ f"{filepath}:{i}: utcnow without parentheses — "+ f"use default=utcnow() or onupdate=utcnow(). "+ f"utcnow is a FunctionElement class; the parens "+ f"create a SQL expression object, not a frozen value."+ )+ exit_code = 1++ if exit_code:+ print()+ print(+ "Hint: utcnow() is correct — it creates a SQL expression "+ "(CURRENT_TIMESTAMP) evaluated per-INSERT by the database."+ )++ return exit_code+++if __name__ == "__main__":+ sys.exit(main())diff --git a/src/local_deep_research/database/models/research.py b/src/local_deep_research/database/models/research.pyindex a27c55c7a4..86e2f05ae5 100644--- a/src/local_deep_research/database/models/research.py+++ b/src/local_deep_research/database/models/research.py@@ -16,6 +16,7 @@ from sqlalchemy import (Text,)from sqlalchemy.orm import relationship+from sqlalchemy_utc import UtcDateTime, utcnowfrom ...constants import ResearchStatusdiff --git a/tests/hooks/test_check_utcnow_parens.py b/tests/hooks/test_check_utcnow_parens.pynew file mode 100644index 0000000000..bf1b73e63c--- /dev/null+++ b/tests/hooks/test_check_utcnow_parens.py@@ -0,0 +1,160 @@+"""+Tests for the check-utcnow-parens pre-commit hook.++Verifies that the hook flags default=utcnow and onupdate=utcnow+(without parentheses) while allowing the correct default=utcnow()+and server_default=utcnow() patterns.+"""++import subprocess+import tempfile+from pathlib import Path+++HOOK_SCRIPT = (+ Path(__file__).parent.parent.parent+ / ".pre-commit-hooks"+ / "check-utcnow-parens.py"+)+++def _run_hook(content: str) -> subprocess.CompletedProcess:+ """Write content to a temp .py file and run the hook against it."""+ with tempfile.NamedTemporaryFile(suffix=".py", mode="w", delete=False) as f:+ f.write(content)+ f.flush()+ return subprocess.run(+ ["python", str(HOOK_SCRIPT), f.name],+ capture_output=True,+ text=True,+ )+++# =========================================================================+# Should flag (exit code 1)+# =========================================================================+++class TestFlagsIncorrectPatterns:+ """Patterns that must be caught by the hook."""++ def test_default_without_parens(self):+ result = _run_hook(+ "created_at = Column(UtcDateTime, default=utcnow, nullable=False)\n"+ )+ assert result.returncode == 1+ assert "utcnow without parentheses" in result.stdout++ def test_onupdate_without_parens(self):+ result = _run_hook(+ "updated_at = Column(UtcDateTime, onupdate=utcnow, nullable=False)\n"+ )+ assert result.returncode == 1+ assert "utcnow without parentheses" in result.stdout++ def test_both_default_and_onupdate_without_parens(self):+ result = _run_hook(+ "updated_at = Column(UtcDateTime, default=utcnow, onupdate=utcnow, nullable=False)\n"+ )+ assert result.returncode == 1+ assert "utcnow without parentheses" in result.stdout++ def test_default_without_parens_trailing_paren(self):+ """default=utcnow) — missing opening paren."""+ result = _run_hook("created_at = Column(UtcDateTime, default=utcnow)\n")+ assert result.returncode == 1++ def test_default_without_parens_multiline(self):+ result = _run_hook(+ "updated_at = Column(\n"+ " UtcDateTime, default=utcnow, onupdate=utcnow, nullable=False\n"+ ")\n"+ )+ assert result.returncode == 1++ def test_default_with_spaces_around_equals(self):+ result = _run_hook(+ "created_at = Column(UtcDateTime, default = utcnow, nullable=False)\n"+ )+ assert result.returncode == 1+++# =========================================================================+# Should pass (exit code 0)+# =========================================================================+++class TestAllowsCorrectPatterns:+ """Patterns that must NOT be flagged."""++ def test_default_with_parens(self):+ result = _run_hook(+ "created_at = Column(UtcDateTime, default=utcnow(), nullable=False)\n"+ )+ assert result.returncode == 0++ def test_onupdate_with_parens(self):+ result = _run_hook(+ "updated_at = Column(UtcDateTime, onupdate=utcnow(), nullable=False)\n"+ )+ assert result.returncode == 0++ def test_server_default_with_parens(self):+ result = _run_hook(+ "created_at = Column(UtcDateTime, server_default=utcnow(), nullable=False)\n"+ )+ assert result.returncode == 0++ def test_both_with_parens(self):+ result = _run_hook(+ "updated_at = Column(UtcDateTime, default=utcnow(), onupdate=utcnow(), nullable=False)\n"+ )+ assert result.returncode == 0++ def test_no_utcnow_at_all(self):+ result = _run_hook("name = Column(String(100), nullable=False)\n")+ assert result.returncode == 0++ def test_utcnow_in_comment(self):+ """Comments mentioning utcnow() should not be flagged."""+ result = _run_hook(+ "# Note: created_at uses default=utcnow() in the model\n"+ )+ assert result.returncode == 0++ def test_utcnow_import(self):+ result = _run_hook("from sqlalchemy_utc import UtcDateTime, utcnow\n")+ assert result.returncode == 0++ def test_utcnow_assignment(self):+ """Direct assignment like existing_rating.created_at = utcnow()."""+ result = _run_hook("existing_rating.created_at = utcnow()\n")+ assert result.returncode == 0++ def test_empty_file(self):+ result = _run_hook("")+ assert result.returncode == 0+++# =========================================================================+# Output format+# =========================================================================+++class TestOutputFormat:+ """Verify the error messages include useful context."""++ def test_shows_filename_and_line(self):+ result = _run_hook(+ "x = 1\n"+ "created_at = Column(UtcDateTime, default=utcnow, nullable=False)\n"+ )+ assert result.returncode == 1+ assert ":2:" in result.stdout # Line 2++ def test_shows_hint(self):+ result = _run_hook(+ "created_at = Column(UtcDateTime, default=utcnow, nullable=False)\n"+ )+ assert "Hint:" in result.stdout+ assert "SQL expression" in result.stdout