Fix --since in welcomebot-reputation
docker-build-push / build-push (push) Successful in 4s

A relative bound has to be datetime('now', '-24 hours'); datetime('-24 hours')
returns NULL, so the comparison was false for every row and --since silently
reported nothing rather than erroring. Caught when a --since '-10 minutes'
came back empty for queries that had demonstrably just happened.

Absolute forms ('2026-09-13') still take the single-argument path.
This commit is contained in:
pmb committed 2026-09-13 16:40:30 -07:00
1 parent 1bfbcfdac3
commit 37feb109b3
1 file changed
+15 -3
+15 -3
View File
@@ -92,6 +92,18 @@ def limited(sql):
return sql if limit == "all" else f"{sql} LIMIT {int(limit)}"
def since_expr(column):
"""SQL for the --since bound.
A leading +/- means "relative to now" — sqlite needs that spelled
datetime('now', '-24 hours'), NOT datetime('-24 hours'), which returns
NULL and silently matches no rows.
"""
if since.startswith(("+", "-")):
return f"{column} >= datetime('now', ?)"
return f"{column} >= datetime(?)"
def tables_exist():
names = {r[0] for r in conn.execute(
"SELECT name FROM sqlite_master WHERE type = 'table'")}
@@ -106,7 +118,7 @@ if not tables_exist():
if mode == "stats":
where, params = [], []
if since:
where.append("queried_at >= datetime(?)")
where.append(since_expr("queried_at"))
params.append(since)
clause = (" WHERE " + " AND ".join(where)) if where else ""
row = conn.execute(
@@ -150,7 +162,7 @@ if mode == "blocks":
where.append("kind = ?")
params.append(kind)
if since:
where.append("first_blocked_at >= datetime(?)")
where.append(since_expr("first_blocked_at"))
params.append(since)
clause = (" WHERE " + " AND ".join(where)) if where else ""
rows = conn.execute(limited(
@@ -179,7 +191,7 @@ if kind:
where.append("kind = ?")
params.append(kind)
if since:
where.append("queried_at >= datetime(?)")
where.append(since_expr("queried_at"))
params.append(since)
clause = (" WHERE " + " AND ".join(where)) if where else ""