Repository navigation
storage: Match Decimal columns' 20-place precision - #7866
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Decimal truncation can bypass secondary-key uniqueness checks and store duplicate unique values, while the unpinned behavior also lets dependent tests appear as clean passes.
2 open issues
What changed in this PR
This PR updates the AL runtime’s database write normalization to match locally measured Business Central Decimal precision.
Changes:
- Truncate stored Decimals toward zero to 20 fractional places without changing the record buffer.
- Refuse Decimal primary-key values that require truncation.
- Add regression tests and document the measurements and remaining evidence gaps.
| File | Description |
|---|---|
docs/probes-needed.md |
Tracks Decimal storage behavior and pending probes. |
docs/decimal-store-probe.md |
Records local BC measurements and unmeasured cases. |
crates/al-vm/tests/store/main.rs |
Registers the Decimal storage test module. |
crates/al-vm/tests/store/decimal_store_truncation.rs |
Tests Insert/Modify truncation, buffer preservation, and primary-key handling. |
crates/al-vm/src/sqltime.rs |
Adds Decimal storage truncation and primary-key refusal. |
Review effort: Balanced
| .into(), | ||
| )); | ||
| } | ||
| row[i] = Value::Decimal(cut); |
| (RtType::Decimal, Value::Decimal(d)) => { | ||
| let cut = d.round_dp_with_strategy(20, rust_decimal::RoundingStrategy::ToZero); | ||
| if cut != *d { |
StefanMaron
left a comment
There was a problem hiding this comment.
Thank you for digging into this. The measurement makes sense given the decimal(38,20) column you already
found in your earlier issue, and I like that you refuse the primary key case instead of guessing.
I can't merge it as it is, for these reasons:
- Filters. After this change a row stored from
1000 / 3600000holds the cut value, but
SetRange(Amount, 1000 / 3600000)still compares with the uncut value. Today that filter finds the row;
with this PR it would not. Your notes say filters are not measured yet. I expect BC cuts the filter value
the same way, so we would swap a correct answer for a wrong one. Storing and filtering need to land together. - The corpus is our only oracle. Could you turn the probe into a test on the corpus repository
(BusinessCentral.AL.Language.Tests)? Its CI runs on BC 27, 28 and 29. Please include: the values from your
table, the filter cells (=, <, >, a range, with both the full and the cut value), a Decimal primary key,
aUnique = truesecondary key, and a temporary table. - Until the corpus pins it, the cut must be registered as an assumption (an entry under
crates/al-builtins/src/assumptions/,assumecalled when the value really changes, and
docs/probes-needed.mdregenerated with--assumptions-docrather than a hand-written row). - A
Unique = truekey over a Decimal field has the same problem as the primary key: two values can become
equal after the cut. Please refuse that case too. - This runs for every Decimal on every database write. Please check
d.scale() > 20before rounding and
share a before and after timing. - Small things:
sqltime.rsis about date and time columns, so a small module of its own (called from
store) would be easier to find; and please remove the container name from the docs file.
If you prefer, open the corpus test first and I will line up the runner side once its results are in.
|
Measured on BC 27.5, 28.5, and 29.1: persisted Decimal fields truncate values to database precision while the AL record buffer retains the supplied value. Filters and Decimal primary-key lookups resolve against persisted values; a unique Decimal secondary-key collision after storage rejects Insert/Modify, while Rename raises Corpus probe: aldevtools/BusinessCentral.AL.Language.Tests#1427 (draft; CI awaiting repository administrator approval). |
|
Thanks for measuring on BC 27.5, 28.5 and 29.1: stored values are cut, the record buffer keeps the full value, filters and primary-key lookups use the stored value, a unique secondary-key collision fails Insert and Modify, Rename raises Next is corpus pull request aldevtools/BusinessCentral.AL.Language.Tests#1427. When it is ready for review, I approve its CI run and review it. This pull request still needs the other points from my review. Your measurement shows filters compare with the stored value, so the filter change has to be in this pull request too. The other points:
|
|
Thank you for this pull request. I am sorry the review took 10 days. I saw you said it is not ready yet, so treat this as early feedback. Verdict: needs a rebase on main, then changes. Conflict:
The review flow changed on 2026-11-21. After the fixes, merge main, add the neighbor folder ( Generated by an AI agent (Claude) working for Stefan Maron. |
|
Thank you for this pull request, and sorry it waited so long without a review. I'm going to finish it on our side now, so you do not need to do anything more: we merge the current main, add the neighbor check folder the new review flow needs, review it and land it. Your commits stay in the history with your name. If you would rather finish it yourself, say so here and I'll stop. Generated by an AI agent (Claude) working for Stefan Maron. |


n/a (no linked issue)
What changed
Evidence from real Business Central (required)
Where the behavior is pinned
Not pinned yet. The probe PR contains the measurements; the assumption registry entry is part of the pending follow-up.
Shapes that keep today's behavior
Temporary records keep their input precision; writes of a Decimal primary key requiring truncation are refused. Primary-key lookups, filtering and unique secondary keys still need the requested follow-up.
Checks
al-test-cli --root . --baseline-diff: no regression; stale lines deleted (--prune-not-passing) (the unpublished follow-up has XMLport regressions on BC 27.5, 28.5, and 29.0; further evidence is needed)./check.sh(not run locally; PR CI is the project gate)Earlier validation of the published branch:
cargo fmt --all -- --check: passed.cargo test -p al-vm --test store decimal_store_truncation: passed after rebase.cargo test -p al-vm --test store: passed before rebase.cargo clippy -p al-vm --all-targets: passed before rebase.