Repository navigation
knowledge(upgrade): upgrade code must not use ChangeCompany - #210
Jesper Schulz-Wedde (JesperSchulz) merged 3 commits into
Conversation
Addresses ADO bug 651092. Upgrade and feature data update code must run in the context of the company being upgraded; ChangeCompany leaves triggers, events and upgrade tags in the calling company and races the target company's own upgrade. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Reviewed 4e33ca87e2e69979747dfbe090ed5bc798fd043c. The central company-context guidance is well founded: PerCompany upgrade triggers execute in company-specific system sessions, PerDatabase triggers have no open company, ChangeCompany does not move trigger execution context, and Feature Management schedules migration tasks for a named company. Three merge-critical issues remain:
- Both companions are not self-contained.
no-changecompany-in-upgrade.good.al:13and.bad.al:8referenceRecord "Sales Order Ext", but neither declares it, and the reviewed tree contains no definition. Include the sample table and both required fields in each independent companion, or use an existing table with a complete declared extension. Otherwise the canonical good example cannot compile. - The changed-path evaluation contract fails.
evaluation/review-fixtures.jsonselects neither the newno-changecompany-in-upgradepair nor the modifiedchangecompany-runs-triggers-in-the-calling-companypair. The exact-head GitHub job and a local run with the PR's actual changed paths both report these missing registrations. Add both pairs to their upgrade/events article overrides and verify bounded positive/clean retrieval; preserve existing selections. - Feature routing is broader than the migration path the article justifies. Article line 26 and
al-upgrade-review.md:47match any method in a codeunit implementing Feature Data Update, includingIsDataUpdateRequired/ReviewDataand their read-only helpers. These are distinct interface phases, not necessarily reachable from scheduledUpdateData. A concrete first-party example isVATSettlActCodeFeatDataUpd.Codeunit.al:IsDataUpdateRequiredcallsCountRecords, which loops companies with ChangeCompany and Count, whileUpdateDatamigrates only the current company. The present route would condemn that preflight solely because it shares the implementation codeunit. Bind feature detection to the actual UpdateData/AfterUpdate execution paths and resolved helpers, rather than the whole codeunit; include a read-only preflight clean control. Keep the intended strict prohibition within the migration execution path. Also include feature-update execution in the skill's applicability/not-applicable scope so an ordinary implementation is not discarded before that route runs.
No source files were changed by this review. As this is my own PR, the blockers are recorded in an exact-head comment rather than a formal change request.
…feature routing - Declare the sample table in both companions so each compiles on its own. - Register no-changecompany-in-upgrade and changecompany-runs-triggers-in-the-calling-company in review-fixtures.json. - Limit the Feature Data Update rule to UpdateData/AfterUpdate and their reachable helpers; read-only IsDataUpdateRequired/ReviewData preflight is permitted and shown as a clean control. - Add feature data update execution to al-upgrade-review applicability and not-applicable scope. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Reviewed 48bd2e2e1be4300004fb97e6bebc26f5fe6af366 against the previous reviewed head. All three blockers are resolved: both companions independently declare the sample table and required fields; both the new upgrade pair and modified events pair are registered without losing existing selections; and feature detection follows UpdateData/AfterUpdate and resolved reachable helpers rather than treating independent IsDataUpdateRequired/ReviewData preflight as migration execution. The expanded applicability scope and added read-only preflight clean control agree with that boundary. The feature execution/preflight distinction is confirmed against FeatureManagementImpl, and changed-path fixture validation passes 226 cases with the contract/skill checks intact. All GitHub checks pass. No remaining merge-critical issue found; content is ready. Formal self-approval is unavailable.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Addresses ADO bug 651092. Upgrade code should run in the context of the company being upgraded, but nothing in the upgrade corpus told the review agent to flag
ChangeCompanythere. A model will happily loop theCompanytable inOnUpgradePerDatabaseand write each company's data throughChangeCompany, which compiles and passes analyzers.What this adds
microsoft/knowledge/upgrade/no-changecompany-in-upgrade.md(+.good.al/.bad.al)PerCompanyupgrade triggers already run once per company in that company's own system session (Learn). Reaching into another company duplicates or races its own upgrade, sees data in an unknown pre/post-upgrade shape, records per-company upgrade tags in the wrong company, and leaves triggers and trigger-event subscribers running in the calling company.Feature Data Updateimplementations too; Feature Management already schedulesUpdate Feature Dataper company viaTaskScheduler.CreateTask(..., CompanyName, ...)(BCAppsFeatureManagementImpl.CreateTask).OnUpgradePerCompanyguarded by a per-company tag; reservePerDatabasefor non-per-company data; schedule per-company tasks instead ofChangeCompanywhen work must start in other companies.ChangeCompany(<name>)on aRecord/RecordRefin an upgrade codeunit, a helper reachable from its triggers, or aFeature Data Updateimplementation. Reads are not exempt. The parameterlessChangeCompany()and runtime code are excluded.al-upgrade-reviewskill: addsChangeCompany,Feature Data Update,UpdateDataas worklist tokens and a worklist bullet routing to the new article.changecompany-runs-triggers-in-the-calling-company.md: cross-reference to the upgrade rule.Notes for reviewers
bc-version: [all],countries: [w1],application-area: [all].Validation
validate_frontmatter.py: 0 errors (2 pre-existing warnings)Test-ReviewFixtures.ps1,Test-ReviewContract.ps1,Test-KnowledgeIndex.ps1,Test-SkillIndex.ps1: passFixes: AB#651092