Skip to content

fix: exclude blank account_ref from engine preview aggregate (#93)#95

Draft
agent-p1p wants to merge 1 commit into
masterfrom
pip/goggles-93
Draft

fix: exclude blank account_ref from engine preview aggregate (#93)#95
agent-p1p wants to merge 1 commit into
masterfrom
pip/goggles-93

Conversation

@agent-p1p

@agent-p1p agent-p1p commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Closes #93

Summary

group_engine_preview() (forensics/views.py) annotated account_ref=Min("account_ref"). Because account_ref is a blank-able CharField and the empty string sorts before any hex value, an engine with any event lacking an account_ref got "" from the aggregate — so the group-detail header engine chips rendered a blank account for an engine that actually has one. Meanwhile timeline_engines() (forensics/analysis.py:907) keeps the first non-empty account_ref, so the same engine showed its real account in the timeline column. The two paths disagreed.

The fix adds filter=~Q(account_ref="") to the aggregate so the preview reports a real account_ref whenever the engine has one, and falls back to "" (via the existing row["account_ref"] or "") only when every event for the engine is blank — exactly matching the timeline's first/any-non-empty semantics. Q was already imported.

Changes

  • forensics/views.py — one-line aggregate change (+ explanatory comment).
  • forensics/tests.py — two regression tests:
    • mixed present/absent account_ref for one engine -> preview reports the real ref
    • all-blank engine -> preview reports ""

Verification

Run locally with DJANGO_DEBUG=1:

  • uv run ruff check . -> All checks passed
  • uv run ruff format --check . -> 19 files already formatted
  • uv run python manage.py test -> 149 tests OK (SQLite)
  • RED/GREEN proof: the new mixed-engine test fails on the old Min("account_ref") (AssertionError: '' != 'aaaa...') and passes with the fix.

Pre-existing master breakage (NOT this PR)

master currently has a conflicting migration graph — two leaf nodes forensics/migrations/0007_add_auditevent_line_hash_engine_index (from #87) and 0007_auditfile_groups (from #80) both branch off 0006 with no merge migration. This makes manage.py test and makemigrations --check fail on master itself (master CI for #87 is red on the Run tests step). This PR's CI will be red for the same reason — it is unrelated to #93 and not introduced here. To run the suite locally I created a throwaway --merge migration, verified all 149 tests pass, then discarded it (not committed). The migration conflict needs a separate fix (a merge migration under the sensitive **/migrations/** path); it is intentionally out of scope for this display-correctness fix.

Sensitive paths

None touched. (forensics/views.py, forensics/tests.py only.)


Open in Stage

group_engine_preview() used Min("account_ref"), which returns "" for any
engine that has at least one event without an account_ref, since the empty
string sorts before any hex value. The shell preview then rendered a blank
account for an engine that actually has one, disagreeing with
timeline_engines() (which keeps the first non-empty account_ref).

Add filter=~Q(account_ref="") to the aggregate so a real account_ref is
reported whenever the engine has one, falling back to "" (via the existing
row["account_ref"] or "") only when every event is blank. This matches the
timeline's first/any-non-empty semantics.

Adds two regression tests covering the mixed present/absent case and the
all-blank fallback.

Closes #93
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@agent-p1p, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 30 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96e5eb39-4d82-4bb6-8dec-708396447aee

📥 Commits

Reviewing files that changed from the base of the PR and between 94630b0 and 042b805.

📒 Files selected for processing (2)
  • forensics/tests.py
  • forensics/views.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pip/goggles-93

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@stage-review

stage-review Bot commented Jun 22, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 2 individual chapters for you:

Title
1 Exclude blank account_ref from engine preview aggregate
2 Add regression tests for engine preview account reporting
Open in Stage

Chapters generated by Stage for commit 042b805 on Jun 22, 2026 12:28pm UTC.

@agent-p1p

Copy link
Copy Markdown
Contributor Author

Adversarial review: no PR-diff blockers

I reviewed PR #95 against issue #93.

Findings:

  • Blocking: 0
  • Suggestions: 0
  • Nitpicks: 0

What I checked:

  • group_engine_preview() now excludes blank account_ref values in the aggregate, so an engine with mixed blank/non-blank refs reports a real account ref instead of "".
  • Existing all-blank behavior is preserved via the row["account_ref"] or "" fallback.
  • Regression tests cover both mixed and all-blank engines.
  • The PR diff only touches forensics/views.py and forensics/tests.py; no sensitive paths touched.

Local verification:

  • uv run ruff check . -> pass
  • uv run ruff format --check . -> pass
  • Direct targeted Django tests currently fail before execution because master has a pre-existing divergent migration graph.
  • With a reviewer-only temporary empty merge migration depending on both 0007 leaves, the two new targeted tests pass and the full suite passes: 149 tests OK.

CI note:

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.

group_engine_preview uses Min(account_ref), which returns "" when some events lack an account_ref — disagrees with the timeline engine list

1 participant