Skip to content

fix(macros): sort offline query JSON keys - #4370

Open
Boulea7 wants to merge 1 commit into
transact-rs:mainfrom
Boulea7:fix/sqlx-4339-deterministic-query-json
Open

fix(macros): sort offline query JSON keys#4370
Boulea7 wants to merge 1 commit into
transact-rs:mainfrom
Boulea7:fix/sqlx-4339-deterministic-query-json

Conversation

@Boulea7

@Boulea7 Boulea7 commented Aug 10, 2026

Copy link
Copy Markdown

Does your PR solve an issue?

Fixes #4339.

This makes cargo sqlx prepare emit deterministic offline metadata by recursively sorting JSON object keys before writing. Array order and scalar values remain unchanged, and generated files retain their trailing newline.

Is this a breaking change?

No. The generated JSON remains semantically equivalent; only object-key order becomes deterministic.

Testing

  • cargo +stable fmt --all -- --check
  • cargo test -p sqlx-macros-core --features 'macros,sqlite' query::data::tests::
  • cargo test -p sqlx-cli --no-default-features --features sqlite --test prepare repeated_sqlite_prepare_is_byte_stable

The repository's pinned Rust 1.94 toolchain does not have the rustfmt component installed in this environment, so the formatting check used the installed stable rustfmt 1.9.0.

AI assistance

This change was developed with AI assistance.

Canonicalize every JSON object before writing offline query metadata so repeated prepare runs produce byte-stable files.

Add recursive ordering, SQLite fixture, and cargo-sqlx prepare regression coverage.

Developed with AI assistance.
@Boulea7
Boulea7 force-pushed the fix/sqlx-4339-deterministic-query-json branch from 4e3712e to a30eb56 Compare August 10, 2026 18:23
@Boulea7

Boulea7 commented Aug 11, 2026

Copy link
Copy Markdown
Author

The failed SQLCipher job appears unrelated to this diff: a30eb56 and the previous green 4e3712e have identical trees, and all five SQLCipher tests passed before the exit-time segfault. The CI-equivalent command also passed locally, including 20 repeated host runs and 20 Ubuntu 24.04 runs; the same exit signature has occurred on unrelated branches. Could a maintainer please rerun the failed SQLite job or matrix?

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.

cargo sqlx prepare produces non-deterministic files

1 participant