Migrations: Fix NPoco auto-select breaking retrust FK migration#22270
Merged
Migrations: Fix NPoco auto-select breaking retrust FK migration#22270
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a SQL Server-only upgrade migration failure caused by NPoco auto-select misinterpreting a raw T-SQL BEGIN TRY block and generating invalid SQL.
Changes:
- Prefixes the migration’s raw T-SQL with a leading semicolon to bypass NPoco
AutoSelectHelperrewriting. - Documents the rationale inline, referencing the empty
[TableName("")]DTO attributes that trigger the invalidFROM []construction.
AndyButland
added a commit
that referenced
this pull request
Mar 27, 2026
Prevent NPoco auto-select from breaking retrust migration.
Contributor
Author
|
Cherry-picked to |
This was referenced Apr 2, 2026
Open
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.
Description
In 17.3 we've added a migration that re-trusts foreign key constraints that have become historically untrusted, primarily through use of SQL bulk inserts - see #21744.
We had #22227 raised against that - that it was attempting to work with non-Umbraco tables and also didn't correctly handle exceptions. This was fixed in #22229 and released in 17.3.0-rc2.
Unfortunately I didn't test that properly, as although it was verified to by-pass non-Umbraco tables, the fix introduced an issue with the actual re-trusting of constraints (in my test database, I no longer had any, so I didn't see it).
So this PR fixes that error.
You would see it with an install of 17.3.0-rc2 when you have a database containing untrusted constraints, with an exception thrown of
An object or column name is missing or empty... Aliases defined as "" or [] are not allowed) in theRetrustForeignKeyAndCheckConstraintsmigration.The cause is NPoco's
AutoSelectHelperprependingSELECT ... FROM []when raw SQL doesn't start with a recognized keyword (SELECT,EXEC, etc.). The TRY/CATCH block starts withBEGIN, which triggers auto-select against the empty[TableName("")]DTO attribute, producing invalid SQL.To fix, a leading semicolon
;is used, which bypasses NPoco's auto-select.Testing
Requires SQL Server (not SQLite).