Skip to content

[kind/bug] BIGINT cell values lose precision past 2^53 #502

Closed

Description

@EVWorth

Context

Surfaced while adding tauri-specta (#502). specta refuses to export u64/i64 to TypeScript by default, precisely to stop this class of bug — which made an existing one visible.

Problem

SqlValue carries cell values across IPC:

pub enum SqlValue {
    Int(i64),
    UInt(u64),
    ...
}

serde_json serialises these as JSON numbers, and JSON.parse truncates anything past 2^53 into a double. So a BIGINT column holding e.g. 9007199254740993 is displayed, copied and exported by the grid as 9007199254740992.

This is not new — it is how the app has always behaved, and the hand-written TypeScript typed these as number. In #502 the fields are annotated #[specta(type = f64)], which documents the existing lossy round-trip rather than introducing or fixing it.

Impact

Silent and plausible-looking: no error, just a wrong digit. Worst in the paths where the value is trusted — copy cell, copy row, copy as INSERT, and CSV/JSON/SQL export — because a truncated id can be pasted straight into another query.

Snowflake ids, BIGINT UNSIGNED primary keys and hash columns are the realistic cases.

Options

  1. Serialise the affected variants as strings (#[serde(with = ...)] plus #[specta(type = String)]), and have the grid render them as text. Lossless. Costs a type change at the boundary and some care wherever a cell value is treated as numeric.
  2. Keep numbers but detect |v| > Number.MAX_SAFE_INTEGER on the Rust side and send those as strings. Narrower blast radius, but a union type to handle in the grid.
  3. Accept and document. Cheapest, still wrong for real BIGINT keys.

Option 1 is the honest fix; option 2 limits churn.

Where

  • src-tauri/crates/mas-core/src/models/query.rs — SqlValue::Int / SqlValue::UInt
  • src/components/grid/ResultsGrid.tsx — display and the copy/export paths
  • src-tauri/crates/mas-export/src/lib.rs — CSV/JSON/SQL export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions