Skip to content

fix(storage/cosmosdb): reject non-string create/update ids without panic - #276

Open
MrBeldum wants to merge 3 commits into
tink3rlabs:mainfrom
MrBeldum:fix/cosmosdb-update-create-string-ids
Open

MrBeldum wants to merge 3 commits into
tink3rlabs:mainfrom
MrBeldum:fix/cosmosdb-update-create-string-ids

Conversation

@MrBeldum

@MrBeldum MrBeldum commented Oct 5, 2026

Copy link
Copy Markdown

Summary

Sibling to #275.

CreateContext asserted partition keys with pk.(string), and UpdateContext did the same for id and pk after merging. A non-string value (for example a numeric id from JSON) panicked instead of returning an error.

Validate with nonEmptyString before touching the client on create, and before ReplaceItem on update — the same approach as the DeleteContext id guard.

Test plan

  • go test ./storage/ -run 'TestNonEmptyString|TestCosmosDBCreateContextRejects'

CreateContext asserted partition keys with pk.(string), and UpdateContext
did the same for id and pk after merging. A non-string value (e.g. numeric
id from JSON) panicked instead of returning an error.

Validate with nonEmptyString before touching the client on create, and
before ReplaceItem on update — the same approach as the DeleteContext id
guard.

Sibling to tink3rlabs#275.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 779680b6-f058-42c8-b3d7-1e5b1e944ba3
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@Lutherwaves Lutherwaves left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: Closes the Create/Update follow-up from #275, and the new tests fail on the old code.

suggestion (non-blocking): Whichever of #275/#276 merges second could switch DeleteContext to nonEmptyString too, so all three methods share one check and one error wording.

Comment thread storage/cosmosdb.go Outdated
Comment thread storage/cosmosdb.go Outdated
Comment thread storage/cosmosdb.go Outdated
Comment thread storage/cosmosdb_string_test.go Outdated
Comment thread storage/cosmosdb_string_test.go Outdated
@Lutherwaves

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

@Lutherwaves Lutherwaves added enhancement New feature or request priority:low Low priority labels Oct 5, 2026
@MrBeldum

Copy link
Copy Markdown
Author

Addressed in 75817ac — verified just now:

  • gofmt: removed the extra blank line; gofmt -l is clean on the changed files.
  • Unused cosmosStringSample: removed (was staticcheck U1000).
  • Partition-key wording: reworded to "This adapter only builds string partition keys and item ids."
  • Shadowed-variable branch: deduped to a single lookup + one nonEmptyString check.
  • Notes-to-self lines in the test: removed.

One item left as the reviewer framed it: switching DeleteContext to nonEmptyString is deferred to whichever of #275/#276 merges second, to avoid a cross-PR dependency (this branch defines the helper; #275 owns the DeleteContext validation).

Validation: go test ./storage/ -run 'TestNonEmptyString|TestCosmosDB' passes; go vet ./storage/ clean.

These changes were prepared with AI assistance and validated by running the package tests; not personally reviewed/tested by Daniel.

Resolve merge conflict in UpdateContext: keep the PR's validated
idStr/pkStr (no bare type assertions) and upstream's session-token
recording from ReplaceItem.
@MrBeldum

Copy link
Copy Markdown
Author

Resolved the merge conflict with upstream main (merge commit 104c45e). The conflict was in UpdateContext: kept this PR's validated idStr/pkStr (no bare type assertions) and kept upstream's session-token recording from ReplaceItem. Full storage test suite passes locally; CI is the gate for the new head.

Disclosure: this conflict resolution was assisted by AI, reviewed against the PR's intent before pushing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority:low Low priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants