Skip to content

fix(value): validate list and array elements against the declared child type - #55

Open
pratik-saptarshi wants to merge 1 commit into
LadybugDB:mainfrom
pratik-saptarshi:fix/nested-type-validation-c3
Open

pratik-saptarshi wants to merge 1 commit into
LadybugDB:mainfrom
pratik-saptarshi:fix/nested-type-validation-c3

Conversation

@pratik-saptarshi

Copy link
Copy Markdown
Contributor

Addresses #50. Stacked on #47: this branch is based on the head of #47 (fix/decimal-conversion-f1-f3), so until #47 merges the diff includes its commits. The new work is the top two commits.

Problem

Value::List(LogicalType, Vec<Value>) and Value::Array(LogicalType, Vec<Value>) carry a caller-declared child type. The write conversion inserted the converted elements under the declared type without checking them against it, and the engine reinterprets each element at the declared width at storage time:

  • List(Int32, [Int64(4294967301)]) bound into an INT32[] column inserted successfully and read back as Int32(5).
  • Array(Int16, [Int64(70000), Int64(-70000)]) read back as [4464, -4464].

No error at any layer. The binding is the only layer that can catch this, because the engine accepts the internally inconsistent value.

Fix

Every element of a List or Array is validated against the declared child type before conversion; a mismatch returns the new ConversionError::TypeMismatch (declared type, actual type). Types must match exactly, with one exactness-preserving exception: a decimal value may be stored under a declared decimal type with the same scale and at least the value's precision. Nested lists are covered from both sides — an inner list's own elements are validated against its declared child type when it is converted, and the inner list's declared type must match the outer declared type. The validation helper (check_nested_type) is shared so the map (#51) and union (#52) fixes can reuse it.

Tests

  • list_and_array_child_type_mismatch_returns_error — the two reproductions above, a heterogeneous list, a nested list with a mismatched inner declared type, and a decimal exceeding the declared precision.
  • list_and_array_child_type_match_round_trips — matching elements, including a decimal stored under a wider declared precision at the same scale, round-trip unchanged.
  • list_mismatched_child_type_fails_insert — the original database reproduction now fails at execute time instead of storing a truncated element.

Full library test suite: 195 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.
@pratik-saptarshi
pratik-saptarshi force-pushed the fix/nested-type-validation-c3 branch from d7c29d1 to 7f3880d Compare November 14, 2026 04:21
pratik-saptarshi added a commit to pratik-saptarshi/ladybug-rust that referenced this pull request Nov 14, 2026
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 added a commit to pratik-saptarshi/ladybug-rust that referenced this pull request Nov 14, 2026
Restacked onto the restacked PR LadybugDB#55 branch (7f3880d) after parent PR LadybugDB#47 merged. This single commit carries the reviewed residual of 43fcc7b (PR LadybugDB#57) unchanged: per-file added/removed line multisets proven byte-identical to the saved residual before pushing.
@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 d7c29d11, new head 7f3880de; base stays main. The rebuild is a single commit with the change reviewed at the old head: 1 file, +138/−0. Its diff against main matches the saved pre-restack diff, with per-file added and removed line multisets byte-identical. No content changed.

— 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