Skip to content

fix(datastore): serialize native bucket datetimes - #158

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/bucketmodel-datetime-json
Sep 20, 2026
Merged

ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix/bucketmodel-datetime-json

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

  • accept Peewee's native datetime value when serializing bucket metadata
  • keep parsing string values for compatibility with older/storage-dependent rows
  • normalize the result to UTC ISO 8601 as before

Verification

The existing test_create_bucket already covers this exact path and failed before the fix, so this PR does not add duplicate coverage.

Fixes #157

@greptile-apps

greptile-apps Bot commented Sep 20, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no actionable correctness, security, or repository-rule issues identified.

Summary

This PR updates Peewee bucket metadata serialization to accept both native datetime values and persisted string values while retaining UTC ISO 8601 output.

  • Parses legacy or storage-dependent string values as before.
  • Serializes native Peewee datetime values without passing them to the string parser.
  • Preserves the shared bucket metadata shape and UTC normalization.

Reviews (1) · Last reviewed commit: "fix(datastore): serialize native bucket ..."

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

The PR modifies BucketModel.json() in aw_datastore/storages/peewee.py to accept Peewee's native datetime value for the 'created' field, while still parsing string values for compatibility. It assigns self.created to a local variable, converts it to a datetime if it is a string, and then normalizes to UTC ISO 8601 as before.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads.

1 advisory finding (summary-only, not scored)

These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.

⚠️ P2 medium — aw_datastore/storages/peewee.py

This is a fix(...) PR but no test files are included in the diff. Erik's feedback: 'where is the repro & fixes they are supposed to catch' (gptme#3441), 'that measurement should come with a regression test' (gptme#3446). Add a test that would have caught this bug. (Advisory: Erik merged all such PRs but consistently requested tests.)

Add a test file that reproduces the bug before the fix and passes after it.

How this was verified: static preflight: fix-commit + touched-files scan (rule 7)

Files changed (1) — the diff as I read it
  • aw_datastore/storages/peewee.py — Changes BucketModel.json() to handle both datetime and string 'created' values by converting strings via iso8601.parse_date before UTC normalization.

Reviewed 6d5aae47896c · openrouter/deepseek/deepseek-v4-flash-0731 · llm engine · 6s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

@ErikBjare
ErikBjare merged commit 35a4867 into ActivityWatch:master Sep 20, 2026
5 checks passed
ErikBjare added a commit to ActivityWatch/activitywatch that referenced this pull request Sep 26, 2026
* build(deps): bump aw-core to include ActivityWatch/aw-core#158

The pinned aw-core fails to create buckets through aw-server (iso8601
ParseError on the bucket's created time, ActivityWatch/aw-core#157), which
the query parity tests need.

* test: add query parity tests for aw-server vs aw-server-rust

Start both servers on free ports with throwaway data dirs, insert identical
events, run a query corpus through /api/0/query/ and diff the normalized
results. Covers each shared transform on its own, the aw-client canonical
queries and the aw-webui multidevice query, over hand-written edge cases and
seeded random event sets. Also checks invariants on each server's output
(sorting, no overlap after unions and flood, duration conservation).

Current divergences are listed in known_failures.txt as strict xfails, each
attributed to an issue in known_issues.py, so the suite is green now and fails
(XPASS) when a fix lands in the pinned submodules.

Runs in CI in a new query-parity workflow and locally via
make test-query-parity.

* test(query-parity): absolute time tolerance, request timeouts, keep unrun known failures

- Compare times with an absolute 2 us tolerance. The relative term allowed
  about 1.8 s on epoch timestamps. With it gone, the sub-ms precision
  divergence in the fractional scenario shows up (13 more known failures).
- Time out bucket, event and query requests after 60 s.
- --update-known-failures only updates cases that ran, so a filtered or
  interrupted run no longer drops entries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BucketModel.json() crashes with iso8601.ParseError when 'created' is a datetime object

2 participants