Skip to content

fix: preserve existing AniList fields when optional flags are omitted#38

Open
aaravmaloo wants to merge 6 commits intoCosmicPredator:mainfrom
aaravmaloo:main
Open

fix: preserve existing AniList fields when optional flags are omitted#38
aaravmaloo wants to merge 6 commits intoCosmicPredator:mainfrom
aaravmaloo:main

Conversation

@aaravmaloo
Copy link
Copy Markdown
Contributor

Description

Fixes a data-loss bug in chibi update where omitted fields (like Date started, Notes, and potentially others) were being cleared on AniList.

Root cause:

  • The update mutation always included optional fields (startedAt, completedAt, notes, status) even when those flags were not provided by the user.

What changed:

  • Replaced static mutation with a dynamic mutation builder that only includes fields present in payload.
  • In update flow, status is now sent only when --status is explicitly provided.
  • notes is now sent only when non-empty notes are explicitly provided.
  • --status default changed from "none" to "" so omitted status is truly omitted.
  • Added unit tests for mutation generation behavior.

Fixes #37

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📝 Documentation update

Tested Environments

  • Linux (any distro)
  • Windows (10 or 11)
  • MacOS ARM64
  • MacOS Intel

Checklist

  • I have used Gitmojis for my commit messages.
  • My code follows the style guidelines of the Go language.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (leave it unchecked if your changes doesn't need documentation update)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (Ignore this for now 🙂)
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (if applicable)

N/A (CLI/internal mutation behavior change).

Additional context

Validated with:

  • gofmt -w cmd/cmd_update.go internal/api/anilist.go internal/api/mutations.go internal/viewmodel/media_update_handler.go internal/api/mutations_test.go
  • go test ./...

Key behavioral guarantee after this PR:

  • chibi update <id> --progress <n> updates progress only, without wiping unrelated AniList entry fields.

… user didnt pass --status, "none" got mapped to CURRENT, so update requests unintentionally sent a status change.

concerns CosmicPredator#37
…tion(params)`, params) instead of using a static mutation constant.

concerns CosmicPredator#37
`TestMediaEntryUpdateMutation_OmitsUnsetOptionalFields`
`TestMediaEntryUpdateMutation_IncludesProvidedDates` (these mutations)
concerns CosmicPredator#37
…der function `mediaEntryUpdateMutation(params map[string]any)` string.

concerns CosmicPredator#37
(note: also added `hasallkeys` helper)
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.

[🐛] chibi update removes "Date started", "Notes", and potentially other fields

1 participant