Skip to content

fix(value): validate map keys and values against the declared types - #56

Open
pratik-saptarshi wants to merge 2 commits into
LadybugDB:mainfrom
pratik-saptarshi:fix/map-type-validation-c7
Open

pratik-saptarshi wants to merge 2 commits into
LadybugDB:mainfrom
pratik-saptarshi:fix/map-type-validation-c7

Conversation

@pratik-saptarshi

Copy link
Copy Markdown
Contributor

Addresses #51. Stacked on #50 (which is itself stacked on #47): this branch is based on the head of the #50 branch (fix/nested-type-validation-c3), so until #47 and #50 merge the diff includes their commits. The new work is the top two commits, and this PR reuses the ConversionError::TypeMismatch error and the shared check_nested_type helper introduced there.

Problem

Value::Map((key_type, value_type), pairs) repeated the unchecked pattern from #50: pairs were built as key/value structs under the declared types without checking the payload, and the engine reinterpreted keys and values at the declared width at storage time:

  • Declared MAP(STRING, INT32) with an Int64(4294967301) value: insert succeeded, stored value read back as Int32(5).
  • Declared MAP(INT32, STRING) with Int64(4294967301) and Int64(5) keys: insert succeeded, both keys were stored as Int32(5) — the stored map held duplicate keys, with no deduplication.

Fix

Every key is validated against the declared key type and every value against the declared value type before conversion, returning ConversionError::TypeMismatch on a mismatch — the same rule and error as the list/array validation in #50.

Tests

  • map_key_and_value_type_mismatch_returns_error — both reproductions above fail the conversion.
  • map_mismatched_types_fail_insert — the value-mismatch reproduction now fails at execute time instead of storing a truncated value.

Full library test suite: 197 passed, 0 failed.

— Musebot-Astro

…ld type

Restacked onto main at 0bbf510 after parent PR LadybugDB#47 merged. This single commit carries the reviewed residual of d7c29d1 (PR LadybugDB#55) unchanged: per-file added/removed line multisets proven byte-identical to the saved residual before pushing.
Restacked onto the restacked PR LadybugDB#55 branch (7f3880d) after parent PR LadybugDB#47 merged. This single commit carries the reviewed residual of 0645721 (PR LadybugDB#56) unchanged: per-file added/removed line multisets proven byte-identical to the saved residual before pushing.
@pratik-saptarshi
pratik-saptarshi force-pushed the fix/map-type-validation-c7 branch from 0645721 to 764c210 Compare November 14, 2026 04:21
@pratik-saptarshi

Copy link
Copy Markdown
Contributor Author

Restack note: this branch was rebuilt after PR #47 merged into main (merge commit 0bbf5103). Old head 06457212, new head 764c210d. This PR stacks on PR #55's change, so the base is now PR #55's branch fix/nested-type-validation-c3 at its restacked head 7f3880de; GitHub had retargeted the base to main after the PR #47 merge. The rebuild is a single commit with the change reviewed at the old head: 1 file, +64/−0. Its diff against the new base matches the saved pre-restack diff, with per-file added and removed line multisets byte-identical. No content changed.

— Musebot-Astro

@pratik-saptarshi

Copy link
Copy Markdown
Contributor Author

Correction to the restack note above: the base change described there did not take effect. GitHub rejected the retarget because a pull request's base branch must exist in this repository, and PR #55's branch is in the fork, so this PR's base remains main. The branch is rebuilt on PR #55's restacked head 7f3880de as stated, so its diff against main includes PR #55's change until #55 merges. The head, residual, and proof in the note above are unchanged.

— Musebot-Astro

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