bcquality/microsoft/knowledge/upgrade/do-not-make-external-calls-in-upgrade-codeunits.md
Jesper Schulz-Wedde 5bcdc55df9 Sync knowledge articles with review agent instructions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-05 14:08:32 +02:00

1.5 KiB

bc-version domain keywords technologies countries application-area
all
upgrade
upgrade
httpclient
external-service
dotnet
availability
al
w1
all

Do not make external service calls inside upgrade codeunits

Description

The upgrade scope has to complete for the tenant to reach the new version. Any call in the upgrade path that depends on an external service — HttpClient to a partner API, a DotNet interop call, a codeunit that fetches remote configuration — fails closed when the service is unreachable, misconfigured, or slow. The failure blocks the upgrade for every customer whose environment cannot reach the dependency at the moment the upgrade runs, and there is no user present to retry. The scope is specifically code inside codeunits with Subtype = Upgrade or reachable from their triggers.

Best Practice

Defer external calls to runtime code that executes after the upgrade — install-triggered tasks, background job queue entries scheduled by the upgrade, or lazy initialization on first use. The upgrade step should compute a local result or mark work to be done, not perform the remote call itself. Do not apply this rule to ordinary runtime codeunits, pages, tables, install procedures, or background jobs unless they are directly invoked from an upgrade trigger.

Anti Pattern

HttpClient.Get(...) or DotNetType.CallStaticMethod(...) directly in OnUpgradePerCompany, or in a local procedure called from it. The upgrade now depends on network availability to a service the platform does not control.