Repository navigation
fix(PC0036): report SetRecord with a temporary record only when the page reads from the database - #643
Merged
Conversation
…age reads from the database Page.SetRecord positions a page on the record's key; it never hands the record's data to the page. A page whose source is temporary (SourceTableTemporary, a TableType = Temporary table, or an OnFindRecord override) shows that record when it loads it itself, so the call is valid there. Only a database-backed page can never show the temporary data, which is the case the rule now reports. Temporary-ness is taken from the keyword or the table type, and CurrPage is covered. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…xtension of a temporary-source page Also fall back to the receiver's source text in the message when the page instance has no symbol, and record that a pageextension cannot declare OnFindRecord, so the trigger lookup on the target page misses nothing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…OnFindRecord Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PC0036 rested on a misunderstanding of
Page.SetRecord, as TKapitan pointed out in #368 (the issue stays open until the release ships).SetRecordonly positions a page on the record's key; it never hands the record's data to the page. There is no runtime error for a temporary record, and Microsoft's own code uses the pattern freely: an audit of all 324x.SetRecord(y)call sites in the BC 29 source found 14+ temporary arguments, every one targeting a page whose data source is temporary (SourceTableTemporary = true, aTableType = Temporarysource table, or a page serving its own buffer throughOnFindRecord). Examples: Item Tracking Summary, Email Accounts, Privacy Notice, Extension Installation, Suggest Price Lines, the Dataverse option lookups from the issue.The one real pitfall, which motivated the original LinterCop LC0058 request (StefanMaron/BusinessCentral.LinterCop#611), is
CustomerCard.SetRecord(TempCustomer)on a page that reads from the database: the temporary data is never shown and the page silently lands on another record. The rule now reports only that case.What changes
temporaryrecord → page over a database table (Customer Card)temporaryrecord →CurrPageof a database-backed page (also from a pageextension)temporaryrecord → page withSourceTableTemporary = trueTableType = Temporarytable (with or without the keyword) → page over that tabletemporaryrecord → page that declaresOnFindRecord(Invt. Order Tracking Lines pattern)temporaryrecord → page without aSourceTablePage.Run/Page.RunModal(Id, TempRec),GetRecord,SetTableView,SetSelectionFilterTitle, message and description are rewritten to describe the positioning semantics and the working alternatives (
Page.Run/RunModalwith the temporary record, or aSourceTableTemporarypage that loads its own data and usesSetRecordto select). Severity stays Warning: the remaining case is a silent wrong-record bug.Temporary-ness is taken from the keyword or the table type (
IsTemporary()in Common);NavTypeKind.CurrPagewas added toEnumProviderfor the receiver name in the message.Notes
temporarykeyword. That could not be reproduced: the binder derivesIRecordTypeSymbol.Temporaryfrom the keyword only on every SDK version checked (12, 16, 17, 18), the analyzer had not changed since it was added, and the existingTempTableTypeWithoutKeywordfixture (the issue's exact shape) passed before and after. It is moot now, because a page over aTableType = Temporarytable is never reported.SetRecord(Temp)on a referenced database-backed page that serves its data throughOnFindRecordis still reported. No such page is a public lookup target in the Microsoft corpus.Verification
dotnet testPC0036: 18 passed (5 of the newNoDiagnosticfixtures failed on the old analyzer, confirming they pin the change).dotnet test ALCops.sln: all green.ContinuousIntegrationBuild=true(netstandard2.1, net8.0, net10.0): 0 warnings, 0 errors.dotnet format --verify-no-changes,Validate-Rules.ps1: clean./code-review highrounds: no correctness defects; the one rejected finding (anOnFindRecorddeclared in a pageextension) is impossible because the SDK allows no such trigger on pageextensions, now recorded as an SDK fact.🤖 Generated with Claude Code