Export-DbaInstance - Script us_english custom errors before their translations - #10552
Merged
potatoqualitee merged 1 commit intoAug 13, 2026
Merged
Conversation
…nslations sp_addmessage refuses a localized message whose us_english version does not exist yet, and SMO returns UserDefinedMessages sorted by language name. So a French translation was scripted before its us_english original and the generated customererrors.sql could not be replayed. The messages are now ordered the same way Copy-DbaCustomError already orders them. Copy-DbaCustomError and Remove-DbaCustomError already handle this rule, and Start-DbaMigration and Sync-DbaAvailabilityGroup both go through Copy-DbaCustomError, so they are unchanged. Get-DbaCustomError keeps returning the plain SMO order. The integration test now creates a second language for one of its custom errors, drops all custom errors of the instance and replays the exported script, which fails on the old code with the error from the issue. Fixes #10550 (do Export-DbaInstance) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
|
awesome change, thank you 🙏🏼 |
potatoqualitee
deleted the
export-dbainstance-custom-error-language-order
branch
August 13, 2026 13:26
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.
Fixes #10550. Reported and correctly diagnosed by @tivivi63.
Problem
Export-DbaInstancewritescustomererrors.sqlwith the localized version of a message before itsus_englishoriginal, so the generated script cannot be replayed:Mechanism
sp_addmessageonly accepts a localized message once theus_englishversion of that message id exists.Get-DbaCustomErrorenumerates$server.UserDefinedMessages, which SMO returns sorted by message id and then by language name, soFrancaiscomes out beforeus_english.Export-DbaInstancepiped that straight intoExport-DbaScript, preserving the wrong order.Reproduced on the current
developmentsource against SQL Server 2019 (15.0.4430.1); the ordering comes from the SMO collection, not from the server version.What changed
public/Export-DbaInstance.ps1orders the messages before scripting them, the same wayCopy-DbaCustomErroralready does:What deliberately did not change
I swept every command that touches user defined messages:
Copy-DbaCustomErrorus_englishfirst, unchangedRemove-DbaCustomErrorStart-DbaMigration,Sync-DbaAvailabilityGroupCopy-DbaCustomError, unchangedGet-DbaCustomErrorGet-Dba*command imposes one, so the fix belongs in the exportTests
tests/Export-DbaInstance.Tests.ps1now creates a French translation for one of the custom errors it already sets up, and the new test exports, drops every custom error on the instance and replays the exported script.The
AfterAllblock drops whatever custom errors are still present instead of two fixed ids, so a failed replay does not leave the instance dirty.Run against a SQL Server 2019 instance:
🤖 Generated with Claude Code