Skip to content

A list's new line that the table field's OnValidate inserted lands on the row at CurrPage.Update (#8186) - #8187

Merged
StefanMaron merged 7 commits into
mainfrom
flemmingbk-currpage-update-norow-refusal
Nov 17, 2026
Merged

StefanMaron merged 7 commits into
mainfrom
flemmingbk-currpage-update-norow-refusal

Conversation

@FBakkensen

@FBakkensen FBakkensen commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #8186

A List page stands on the line New() started. A SetValue runs the table field's OnValidate, which inserts Rec itself (if "Entry No." = 0 then Insert(true), an AutoIncrement key), and then the control's OnValidate calls CurrPage.Update(). Main refuses the test: "CurrPage.Update on a page that shows no row (empty view or new line) while its view has rows". Business Central leaves the line for the stored row. This branch does the same in exactly the cells the probe and the reporter's repro measured, behind the new assumption list-new-line-code-insert-update. Every other shape keeps main's outcome.

What changed

  • pages/code_inserted_new_line.rs (new) owns the rule:
    • land_on_code_inserted_line, asked by CurrPage.Update() and CurrPage.Update(false): in a measured cell the page leaves the new line for the stored row before the call goes on. Update() then saves it through the usual save path, as a modify (P.MOD(X/);T.M(X/); before the OnValidate ends; OnInsertRecord never runs, nothing is inserted twice). Update(false) saves nothing.
    • The refresh that call asks for (code_inserted_refresh_due) reads the view from its first row, the row again, then OnAfterGetCurrRecord (P.AGR(X);P.AGR(A);P.AGR(X);P.AGR(X);P.AGCR(X); with a row before, P.AGR(X);P.AGR(X);P.AGCR(X); on an empty view).
    • previous_on_code_inserted_row, asked by end_move_without_read: Previous() on that row, when it is the view's only row and the test only read and wrote controls since, answers false, runs nothing and keeps the edit unsaved; Next() then saves it.
    • refuse_error_after_landing, asked by validate_step_close: a validation that ends with an AL error after the move is refused.
  • The entry condition is one predicate, code_inserted_cell. Each fact cites ListNewLineCodeInsertUpdate.al:
    • The page: PageType List, a database source, no part, no page extension, no event subscriber. It declares only PageType, SourceTable, AutoSplitKey (true), ApplicationArea and UsageCategory. Its own triggers are none, or exactly OnNewRecord, OnInsertRecord, OnModifyRecord, OnAfterGetRecord and OnAfterGetCurrRecord.
    • The open: the test's OpenEdit on a view without filters, or a Page.RunModal(Id, Rec) statement in Edit mode. The record has no filter, or (the reporter's repro) one SetRange in group 0 on the key's Code field to the line's value. The view is in ascending primary key order, without MarkedOnly.
    • The calls: the test called New() and then the SetValue that runs now, nothing else.
    • The key and the insert: the primary key is a Code field, then an AutoIncrement Integer field. The table has no table extension and no event subscriber. The row was written after the line started and before the control's own OnValidate began. A store mark taken when that trigger starts (run_control_onvalidate, PageState::control_onvalidate_writes) decides this.
    • The view: the inserted row is last, alone or after one row with the same Code value.
    • The cells, as (triggers, AutoSplitKey, open, call): the five triggers with AutoSplitKey under OpenEdit (Update(), Update(false)) and under an unfiltered RunModal (Update()); the five triggers without AutoSplitKey under OpenEdit (Update()); no trigger with AutoSplitKey under OpenEdit (Update()) and under the RunModal filtered to one group (Update(), the repro). Update(true) written out is left to main.
  • PageState has three fields of the rule: refresh_from_code_inserted_line (taken by every refresh), code_inserted_row (taken by every move), and control_onvalidate_writes (set only while the control's OnValidate runs). forget_code_inserted_line clears the first two when the page opens or closes, and after a refused validation.
  • reread_view_from_row moves out of refresh_after_validate_filter (actions.rs) into refresh_new_line.rs, together with finish_validate_refresh, and both paths use it. refresh_after_validate_filter does what it did before.
  • stale_rename::row_version is now pub(crate) (the one reader of SystemRowVersion in a row buffer).
  • Ratchets: actions.rs is now 3391 lines (cap lowered from 3413), pageops.rs::test_page_op_inner 531 (from 535; the refresh request of CurrPage.Update moved into ask_update_refresh). controls.rs::control_set_value_now stays at its cap of 770.

Evidence from real Business Central (required)

Where the behavior is pinned

  • Not pinned yet: the assumption list-new-line-code-insert-update (crates/al-builtins/src/assumptions/list-new-line-code-insert-update.rs) awaits the probe file above. docs/probes-needed.md has its row.
  • The cells it answers: ListNewLine_FieldValidateInserts_* and ListNewLine_RunModal_* (page 97032, :515-617), ListNewLine_NoAutoSplitKey_* (page 97033, :539-560), ListNewLine_NoPageTriggers_* (page 97039, :783-810), and the reporter's two tests.

Shapes that keep today's behavior

  • Refused now, answered by main: an AL error that ends the validation after CurrPage.Update() or Update(false) moved the page onto the row (asserterror around the SetValue; the error rolls the insert back). Main fails the test there, and BC is not measured. Undoing the move would not give main's result: Update() has already run OnModifyRecord and the table's OnModify on the row. So the validation is refused.
  • Main's refusal, as the review found (each shape has a test in Issue8186Neighbors.al):
    • A filter that leaves the inserted row out: the test's Filter.SetFilter(Name, 'A'), or a RunModal record filtered on Name.
    • Two rows before the line, or a row after it.
    • The control's OnValidate inserts Rec itself (Rec.Insert(true); CurrPage.Update();).
    • ModifyAllowed = false, a descending SourceTableView, a page opened with Trap and Page.Run, a primary key of the AutoIncrement field alone.
    • A read of a control between New() and the SetValue.
  • Main's answer: Update(false) on the page without AutoSplitKey (not measured) keeps main's result (the close inserts the line a second time).
  • The marks are cleared: after Close() and a second OpenEdit on the same TestPage variable, Previous() on the only row saves the Value typed, as on a plain list.
  • A host with parts keeps the refusal. The probe measures one (page 97036: OnAfterGetRecord only, two CardPart FactBoxes linked to the line's key). There Business Central's parts read at steps the runner does not model, already before this change: F.AGCR(); at the open of an empty view, no relink at New() (the parts keep showing the row before) and F.AGCR(); at the start of the next SetValue, a re-read of the parts after the SetValue on Value under OpenEdit, P.AGR(X); before Previous saves, and F.AGCR(); when Next starts a new line. The runner already fails these four cells at the open or at New() on main, and still does. They are a FactBox gap of their own, outside this change: A List page's linked CardPart FactBox on the new line: BC keeps the part on the row before after New() and runs its OnAfterGetCurrRecord on the blank line; al-runner blanks the part at New() and runs no part trigger #8188.
  • Also kept: DelayedInsert, a Worksheet or other page type, any other page property or trigger, Update(true) written out, SaveRecord, OpenNew, OpenView, a temporary source, a line not started by New(), and a row the validation did not insert.

Checks

  • A test that failed before this change and passes now: issue_8186_code_inserted_new_line_lands_on_the_row runs the probe file (fixture Issue8186Probe.al) and the reporter's repro (Issue8186.al). Red on main: every cell not run with the refusal above. Green here: each passes, flagged.
  • Tests for the review's shapes, red on the earlier head of this branch and green now:
    • issue_8186_error_after_the_landing_is_refused: the error shapes are refused.
    • issue_8186_unmeasured_views_and_opens_keep_main_refusal: the filter, row-count, control-insert, open and call neighbors keep main's refusal without the mark; Update(false) without AutoSplitKey keeps main's answer.
    • issue_8186_unmeasured_page_and_key_keep_main_refusal: ModifyAllowed, SourceTableView and the AutoIncrement-only key.
    • issue_8186_reopen_forgets_the_landing: the marks are cleared at close and open.
  • issue_8186_unmeasured_neighbors_stay_refused: DelayedInsert, Worksheet, Update(true) and a CardPart keep main's refusal.
  • al-test-cli --root . --baseline-diff, run on BC 27, 28 and 29 with the head binary: no stale lines, and no regression in pages or any other area this touches. On this Windows machine the same 7 cases of streams and types (Windows code pages, BC 27.5 only) and 4 of dotnet (CRLF and .NET texts) fail on every major. They come from the host and read no page.
  • ./check.sh: not run, per the PR CI rule. Run locally: cargo test -p al-test-cli --test suite outside_fb_repros, --test fn_length_ratchet --test file_size_ratchet --test os_access_ratchet, cargo test -p al-test-cli --lib assumption, cargo test -p al-builtins --lib, cargo test -p al-version --test no_version_literals, cargo clippy -p al-vm -p al-builtins -- -D warnings, cargo clippy -p al-test-cli --test suite -- -D warnings, cargo fmt --all. The assumption merge check needs bash, which this machine lacks.
  • I signed the contributor agreement (see CONTRIBUTING.md)
  • No machine names, URLs, credentials, tenant ids or customer code in the change or this text

The partner test behind #8186 runs on a page with CardPart FactBoxes, so it stays refused until the FactBox gap above (#8188) is closed.

FBakkensen and others added 3 commits November 16, 2026 14:17
… the row at CurrPage.Update (#8186)

A List page without parts on the line New() started: the table field's OnValidate inserts Rec itself (an AutoIncrement key) and the control's OnValidate calls CurrPage.Update() or Update(false). Main refused it. BC (corpus pull request 1425, open, measured on BC 29.1) leaves the line for the stored row: Update() modifies it, Update(false) saves nothing, the refresh reads the view from its first row, and Previous on the view's only row answers false without a save. New assumption list-new-line-code-insert-update; pages with parts, DelayedInsert, a temporary source, Update(true) written out and other trigger sets keep the refusal.

The refresh that reads the view from its first row moves out of refresh_after_validate_filter into refresh_new_line.rs (reread_view_from_row), shared by both paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… its probe text

The probe ran green on every supported major in corpus CI; name issue 8188 for the FactBox host it leaves refused.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…issue

An entry that names an al-runner issue must await it; the FactBox host it leaves refused is described without the number.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@StefanMaron

Copy link
Copy Markdown
Collaborator

The corpus check is red on its step time guard only: the step took 207 s against a limit of 188 s (1.5 times main's median of 125 s). The work counts of all three majors stay within 10% of main, and the not-passing lists show no regression. So this does not come from your change. I will start the check again.

The probe this depends on, aldevtools/BusinessCentral.AL.Language.Tests#1425, is not merged yet. I review it next. Until it is pinned, the passes here stay flagged.

Corpus pull request 1425 is merged (not pinned yet): the assumption entry, the module comments and the fixture now cite tests/al-language/pages/currpage/ListNewLineCodeInsertUpdate.al by line. metrics/file-sizes.toml: main dropped rows.rs (now under the limit); actions.rs keeps this branch's lower cap.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@StefanMaron

Copy link
Copy Markdown
Collaborator

Thanks for this, Flemming. Corpus PR 1425 is merged. I ran the branch merged with today's main: the 10 measured cells
of ListNewLineCodeInsertUpdate.al pass on BC 27, 28 and 29, the baseline diff is clean on all three, and the Rust tests
pass. The red corpus check was only the step time guard.

Before I merge, the entry condition has to be narrower. It also answers shapes the probe did not measure. I tested each
of these with a small app; main refuses all of them except the first:

  1. An error after CurrPage.Update() in the OnValidate (asserterror around the SetValue). The insert is rolled back, but
    the page stays on the row as if it were stored. With Update(false), a value typed after that is dropped at Close
    without a save; main inserts the line there. Please refuse, or undo the move to the row, when the validation ends
    with an error.
  2. A filter that excludes the inserted row (Filter.SetFilter(Name, 'A') with a row A). The page then shows row A, and the
    next SetValue changes row A. Please require that the inserted row is in the view.
  3. More than one row before the line, or a row after it. The refresh reads P.AGR(X);P.AGR(B);P.AGR(A);..., which the
    probe measures only for one row. Please require an empty view or exactly one row before, and no row after.
  4. The control's OnValidate inserts Rec itself (Rec.Insert(true); CurrPage.Update();). The assumption says the table
    field inserts it. Please require that the row was stored before the control's trigger started.
  5. Also answered and not measured: ModifyAllowed = false (it raises "Page cannot be saved."), a descending
    SourceTableView, a page opened with Trap and Page.Run, and a key that is only the AutoIncrement field.
  6. The two new PageState fields are not cleared when the page closes. After Close and OpenEdit on the same TestPage
    variable, Previous() on the only row skips the save that a plain list makes. Please clear them at open and close.

Small things: docs/codemap.md names update_code_inserted_new_line, the function is land_on_code_inserted_line. The
texts still say corpus PR 1425 is open. Merging main conflicts in metrics/file-sizes.toml (main removed the rows.rs
row). This PR and #8190 both change docs/probes-needed.md and metrics/fn-lengths.toml, so the second one needs a merge.

I can attach my probe app and its output if that helps.

FBakkensen and others added 2 commits November 17, 2026 12:35
Review of #8187: the path answered shapes the probe of corpus PR 1425 did
not measure. The entry is now one predicate, code_inserted_cell: the page
declares only the probe's properties and triggers (no part, extension or
subscriber), it was opened with OpenEdit on an unfiltered view or by a
Page.RunModal statement (unfiltered, or one SetRange on the key's Code
field for the reporter's repro), the test called only New() and the
SetValue, the key is a Code field and an AutoIncrement Integer field, the
table field inserted the row before the control's OnValidate began (a
write mark taken when that trigger starts), and the view holds the row
last, alone or after one row of the same Code. Each cell of the probe is
listed with its lines.

A validation that ends with an error after the move onto the row is
refused. The landing marks are forgotten when the page opens and closes.

Neighbor tests (Issue8186Neighbors.al) show each shape of the review keeps
main's outcome or is refused.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The entry was named update_code_inserted_new_line; the function is land_on_code_inserted_line. Also list the validation hooks and the refresh check.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@FBakkensen

Copy link
Copy Markdown
Collaborator Author

Thanks for the review and the small apps. All six points are fixed in d1c4fdb3f; fae2b76ea updates codemap.md. Each point has a Rust test in outside_fb_repros.rs, with the neighbor shapes in fixtures/outside-fb/Issue8186Neighbors.al.

  1. An error that ends the validation after the move to the row is now refused. Undoing the move cannot give main's result, because Update() has already run OnModifyRecord and the table's OnModify. This is the one shape main answered that now refuses; the PR body says so.
  2. A filter that hides the inserted row, (3) more than one row before the line or a row after it, (4) a row the control's OnValidate inserts, and (5) ModifyAllowed, a descending SourceTableView, Trap with Page.Run and a key that is only the AutoIncrement field now keep main's refusal, without the flag. One predicate, code_inserted_cell, checks the facts the measured cells share, each citing ListNewLineCodeInsertUpdate.al by line, then lists the five cells.
  3. Both PageState fields are cleared at open, at close and after a refused validation. issue_8186_reopen_forgets_the_landing covers Close and OpenEdit on the same variable.

codemap.md and the texts are fixed, and the probes-needed table is regenerated. The baseline diff on 27, 28 and 29 shows no regression or stale line. Whichever of this PR and #8190 lands second needs a main merge for docs/probes-needed.md and metrics/fn-lengths.toml.

@StefanMaron

Copy link
Copy Markdown
Collaborator

Thanks, Flemming. That covers all six points. I'll review the new commits (d1c4fdb3f and fae2b76ea) next and run your neighbor fixtures against main.

About point 1: you are right that undoing the move can't give main's result once Update() has run OnModifyRecord and OnModify. I'll check whether a corpus test measures main's answer for that shape. If none does, the refusal is the right result.

On landing order: I'll land #8190 first, so this one needs the main merge for docs/probes-needed.md and metrics/fn-lengths.toml. I'll tell you when that point comes.

metrics/file-sizes.toml: keep the lower cap of each side (actions.rs from this branch, reports.rs from main).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@StefanMaron

Copy link
Copy Markdown
Collaborator

Thanks, Flemming. I checked the six points from the first review against your new head, and all are fixed:

  • An error after CurrPage.Update in the OnValidate is now refused. Main has no corpus case for that shape, so the
    refusal is right.
  • The entry condition now checks every fact the assumption names: the view, the filters and order, who stored the row,
    the opener, the page properties and the key. Each neighbor from my probe app now keeps main's result.
  • The marks are cleared at open and close. Previous after a second OpenEdit saves the typed value, as on a plain list.
  • The codemap name and the "open" corpus texts are fixed.

I ran your neighbor fixtures on BC 27, 28 and 29 against main and your branch, and the results are as your tests say.

Three small things for a later PR, they do not block this one:

  1. previous_on_code_inserted_row answers false without calling assume(). Today the test is already flagged by the
    landing, but the call would make that explicit.
  2. A second Previous() on the only row saves the typed value through the general rule. BC is not measured there.
  3. Some combinations still take the new path: OnModifyRecord that exits false, Insert(false) in the table field,
    Update() called twice, Rec changed before Update(). It would help to add them to a probe or refuse them.

#8190 lands first. After that I'll land this one through the merge train and resolve the three conflicts with main there myself (parts.rs, docs/probes-needed.md and metrics/fn-lengths.toml), so you don't need to do anything.

@StefanMaron
StefanMaron merged commit 5bb2693 into main Nov 17, 2026
11 checks passed
@StefanMaron
StefanMaron deleted the flemmingbk-currpage-update-norow-refusal branch November 17, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants