Skip to content

fix(query): stop decode failures masquerading as NULL - #509

Merged
EVWorth merged 2 commits into
mainfrom
fix/508-decode-errors-not-null
Aug 28, 2026
Merged

EVWorth merged 2 commits into
mainfrom
fix/508-decode-errors-not-null

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Closes #508. Step 1 of the restructure discussed on #502.

The bug

extract_value decoded each cell with .ok().flatten(), collapsing three different outcomes into one:

.try_get::<Option<f64>, _>(index)
.ok()          // decode error discarded
.flatten()
.unwrap_or(SqlValue::Null)

A genuine SQL NULL, a successful decode, and a failed decode all came out as SqlValue::Null.

Measured against MySQL 8 through the real execute path:

COLUMN d    type=DECIMAL   value=Null      -- DECIMAL(20,4), actually 1.5
COLUMN n    type=DECIMAL   value=Null      -- NUMERIC(10,2), actually 2.5
COLUMN yr   type=YEAR      value=Null      -- YEAR, actually 2026

sqlx refuses DECIMAL outright (built with default-features = false, no rust_decimal/bigdecimal), and YEAR was matched in the DATE | DATETIME | TIMESTAMP | TIME | YEAR arm and asked to decode as a timestamp. Both failures were invisible — the grid, exports, copy-as-INSERT and generated WHERE predicates all saw NULL.

The fix

Every arm now goes through decode_or_text, which keeps the three cases apart. A decode error falls back to the text MySQL sent and logs a warning, so an unsupported type degrades visibly instead of vanishing. That closes the class rather than the two known instances — the next type sqlx can't handle shows up as text with a warning, not as a phantom NULL.

DECIMAL reads as text deliberately, not via f64: f64 would defeat the exactness the column type exists to provide. Getting there needed sqlx's Decode impl directly, since try_get::<String> also refuses DECIMAL (VARCHAR is not compatible with DECIMAL).

Tests

crates/mas-core/tests/type_coverage.rs, against the real database:

  • DECIMAL and NUMERIC round-trip exactly — 12345678901234.5678, no f64 anywhere near it
  • YEAR is UInt(2026)
  • a real NULL is still NULL — the fix must not go the other way
  • BIGINT, FLOAT, JSON, DATETIME, TIME, BLOB, VARCHAR still decode as before

Verified they fail without the fix: reverting executor.rs turns the DECIMAL and YEAR tests red while the other two stay green.

One extra fix

The binding export is now gated on beta-ai. Without the feature the AI commands aren't in the builder, so a plain cargo test quietly regenerated bindings.ts without them — which happened to me while verifying this change. The pre-commit hook caught it, but the export shouldn't be able to write a partial file at all.

Known follow-on

DECIMAL now arrives at the frontend as a string, so toSqlLiteral quotes it in generated INSERTs. That's strictly better than the NULL it emitted before, and gets resolved properly in step 2, where quoting and alignment move to ColumnMeta — the approach both SQLyog and Beekeeper Studio use.

EVWorth and others added 2 commits August 27, 2026 20:15
extract_value decoded each cell with `.ok().flatten()`, collapsing three
outcomes into one: a genuine SQL NULL, a successful decode, and a
*failed* decode all became SqlValue::Null.

The consequence was silent data loss. sqlx refuses DECIMAL entirely
without the rust_decimal/bigdecimal feature, so every DECIMAL and
NUMERIC column rendered as NULL — indistinguishable from a real one,
nothing logged. YEAR did the same, matched in the DATE/DATETIME arm and
asked to decode as a timestamp. Measured against MySQL 8 through the
real execute path.

Each arm now goes through decode_or_text, which keeps the three cases
apart: a decode error falls back to the text MySQL sent and warns, so an
unsupported type degrades visibly instead of vanishing. That closes the
class, not just the two known instances.

DECIMAL is read as text deliberately rather than via f64, which would
defeat the exactness the type exists to provide.

Also gates the binding export on beta-ai. Without the feature the AI
commands are absent from the builder, so a plain `cargo test` quietly
regenerated bindings.ts without them — which happened while verifying
this change.

DECIMAL now reaches the frontend as a string, so generated INSERTs quote
it: better than the NULL it produced before, and resolved properly when
quoting moves to column metadata (#502).

closes #508

Co-Authored-By: Claude Opus 5 <[email protected]>
The tests selected from a type_probe table that existed only on my
machine, so they failed in CI. Each test now creates and drops its own
uniquely-named table, which also lets them run in parallel.

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth merged commit a0d34ab into main Aug 28, 2026
9 checks passed
@EVWorth
EVWorth deleted the fix/508-decode-errors-not-null branch August 28, 2026 01:26
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.

[severity/p0][kind/bug] DECIMAL and YEAR columns silently render as NULL

1 participant