Skip to content

fix: serialize team_name in StatboticsTeamEvent.toJson - #8

Open
cappy-dev wants to merge 1 commit into
Project516:mainfrom
cappy-dev:fix/statbotics-tojson-team-name
Open

fix: serialize team_name in StatboticsTeamEvent.toJson#8
cappy-dev wants to merge 1 commit into
Project516:mainfrom
cappy-dev:fix/statbotics-tojson-team-name

Conversation

@cappy-dev

@cappy-dev cappy-dev commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Problem

StatboticsTeamEvent.fromJson decodes team_name, but toJson left the field out. The toJson doc comment claims the model "round-trips through fromJson for the on-device last-good cache," and the README says models "round-trip through toJson for caching," so a cached record that survives a relaunch comes back with an empty teamName even though /team_events had carried one.

team_name is the one event-scoped name source: /teams accepts an event parameter and ignores it, answering with the global team list. So the loss is silent and the nickname cannot be recovered from any other endpoint that StatboticsClient exposes.

Repro

final original = StatboticsTeamEvent.fromJson({
  'team': 3847,
  'event': '2026txhou',
  'event_name': 'Houston',
  'team_name': 'Spectrum',
  'year': 2026,
  'wins': 1,
  'losses': 0,
  'ties': 0,
  'epa': <String, dynamic>{},
});

final restored = StatboticsTeamEvent.fromJson(original.toJson());
print(original.teamName);   // 'Spectrum'
print(restored.teamName);   // '' (before this fix)

Fix

Add 'team_name': teamName to StatboticsClient (well, lib/src/statbotics_models.dart) toJson, and two round-trip regression tests: one with a nickname, one empty. The empty-name test passes before the fix; the nickname test does not, and it guards the field going forward. dart analyze is clean and the full suite passes (25 tests).

Only team_name was at risk; every other field in toJson already round-tripped, so the added test also asserts the rest of the model.

On behalf of @Project516

Summary by CodeRabbit

  • Bug Fixes

    • Preserved team names when team event records are converted to JSON and restored, preventing cached records from losing nickname information.
    • Correctly handles events where no team name is available.
  • Chores

    • Updated the package version to 0.3.1.
    • Added a changelog entry documenting the fix.

StatboticsTeamEvent.fromJson decodes team_name, but toJson left it out,
so a record cached through toJson and reloaded through fromJson lost the
nickname. The on-device last-good cache round-trips through these two
methods, and team_name is the one event-scoped name source (/teams
ignores its event parameter), so the loss was silent. Add the field to
toJson and two round-trip regression tests.

On behalf of @Project516
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change preserves StatboticsTeamEvent.teamName during JSON serialization and restoration. Tests cover populated and absent names. The package version and changelog now reflect release 0.3.1.

Changes

Team name serialization

Layer / File(s) Summary
Serialization and round-trip validation
lib/src/statbotics_models.dart, test/statbotics_client_test.dart
StatboticsTeamEvent.toJson() now writes teamName as team_name. Tests verify populated and absent names after JSON round trips.
Release metadata
pubspec.yaml, CHANGELOG.md
The package version is 0.3.1. The changelog documents the serialization change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: project516

Poem

A bunny found a missing name,
And tucked it in the JSON frame.
Round trips now keep nicknames bright,
With tests to guard the fields just right.
Version three-one hops in delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: serializing team_name in StatboticsTeamEvent.toJson.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai
coderabbitai Bot requested a review from Project516 August 8, 2026 05:36
@cappy-dev

Copy link
Copy Markdown
Contributor Author

cc @Project516

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Around line 5-7: Rewrite the changelog sentence about
StatboticsTeamEvent.toJson and fromJson so it is grammatical and directly states
that toJson serializes team_name and fromJson preserves it during round trips.
Keep the existing context about nickname preservation without adding unrelated
details.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 840a2294-691d-4e1c-9596-adb53ec19265

📥 Commits

Reviewing files that changed from the base of the PR and between bf8f9b2 and 7f700e7.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • lib/src/statbotics_models.dart
  • pubspec.yaml
  • test/statbotics_client_test.dart

Comment thread CHANGELOG.md
Comment on lines +5 to +7
- `StatboticsTeamEvent.toJson` now serializes `team_name`, so the
round-trip `toJson` advertises through `fromJson` actually preserves the
nickname. Previously the field was decoded but left out of `toJson`, so a

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Correct the malformed round-trip sentence.

Line 6 is not grammatical and does not clearly describe the serialization contract. Use a direct toJson/fromJson statement.

Proposed wording
 - `StatboticsTeamEvent.toJson` now serializes `team_name`, so the
-  round-trip `toJson` advertises through `fromJson` actually preserves the
+  `toJson`/`fromJson` round trip now preserves the
   nickname.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `StatboticsTeamEvent.toJson` now serializes `team_name`, so the
round-trip `toJson` advertises through `fromJson` actually preserves the
nickname. Previously the field was decoded but left out of `toJson`, so a
- `StatboticsTeamEvent.toJson` now serializes `team_name`, so the
`toJson`/`fromJson` round trip now preserves the
nickname.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.md` around lines 5 - 7, Rewrite the changelog sentence about
StatboticsTeamEvent.toJson and fromJson so it is grammatical and directly states
that toJson serializes team_name and fromJson preserves it during round trips.
Keep the existing context about nickname preservation without adding unrelated
details.

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.

1 participant