Skip to content

Fix #2255: serialize dictionary keys invariantly#2753

Open
JKamsker wants to merge 2 commits into
litedb-org:devfrom
JKamsker:bug/2255-dict-key-culture
Open

Fix #2255: serialize dictionary keys invariantly#2753
JKamsker wants to merge 2 commits into
litedb-org:devfrom
JKamsker:bug/2255-dict-key-culture

Conversation

@JKamsker

Copy link
Copy Markdown
Collaborator

Fixes #2255.

Summary

  • Serializes non-string dictionary keys using invariant culture where appropriate.
  • Prevents persisted dictionary field names from changing with CurrentCulture.
  • Keeps existing string-key dictionary behavior unchanged.

TDD / verification

  • Added regression coverage demonstrating culture-dependent dictionary key corruption before the fix.
  • Verified the focused Issue2255 tests and the full net8.0 test project.

Compatibility note

No LiteDB file format change. The fix stabilizes the string representation of dictionary keys going forward.

JKamsker and others added 2 commits June 10, 2026 20:31
…rg#2255)

SerializeDictionary writes non-string keys with key.ToString() (current
culture) while DeserializeDictionary parses them with ConvertFromInvariantString.
Under a comma-decimal culture (de-DE) a Dictionary<double,double> key 9.9 is
stored as "9,9" and cannot be read back, silently losing/corrupting data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
SerializeDictionary used key.ToString(), which is culture-dependent, while
DeserializeDictionary parses keys with ConvertFromInvariantString. Under a
comma-decimal culture (e.g. de-DE) a Dictionary<double,double> key 9.9 was
stored as "9,9" and silently corrupted on read.

Serialize keys via TypeConverter.ConvertToInvariantString (DateTime keeps the
round-trip "o" format, now explicitly invariant), matching deserialization.
Under invariant/en-US cultures the stored output is unchanged ("9.9"), so this
is not a format change for existing readable databases; data previously written
under a comma-decimal culture was already unreadable and cannot be migrated.

Fixes litedb-org#2255.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8640b41-cf0e-4c27-84c5-5dc4d618b38b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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