Skip to content

FIX: Correct SQL Server migration collation - #4247

Merged
Behnam (behnam-o) merged 7 commits into
microsoft:mainfrom
behnam-o:behnam-o/fix-sqlserver-migration-collation
Nov 12, 2026
Merged

Behnam (behnam-o) merged 7 commits into
microsoft:mainfrom
behnam-o:behnam-o/fix-sqlserver-migration-collation

Conversation

@behnam-o

@behnam-o Behnam (behnam-o) commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fix #3920's SQL Server error 102: COLLATE rejects QUOTENAME-delimited collation names.

  • Use the metadata-derived name in both statements after an ASCII allowlist check.
  • Preserve collation, Unicode widths, and nullability; adjust one existing test assertion. No new test files.

& $python -m pytest tests\unit\memory\test_dataset_lifecycle_migration.py -q (existing development-venv Python): 6 passed. Three local-only SQL Server 2022 execution checks also passed, along with lint, formatting, types, and schema checks. Full SQL Server migration chain not run.

Maintainer exception required: & $python -m build_scripts.enforce_alembic_revision_immutability fails as expected because this fixes an existing revision. No checks disabled or bypassed.

Validate the metadata-derived collation before using the bare name required by SQL Server COLLATE. Preserve Unicode widths, nullability, and dataset identity comparisons in both ALTER COLUMN statements.

Exercise the migration on a disposable SQL Server with case-sensitive and case-insensitive collations. Editing this existing revision intentionally requires a maintainer-approved Alembic immutability exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change modifies an existing Alembic revision rejected by the repository’s immutability guard, requiring a maintainer-approved migration-history exception before merge.

No open issues 🎉

What changed in this PR

Fixes the SQL Server Unicode dataset-name migration introduced in #3920, allowing upgrades to proceed without changing existing collation semantics or column constraints.

Changes:

  • Replaces bracket-delimited collation names with bare names validated against an ASCII allowlist and SQL Server’s supported collations.
  • Preserves nullable, unbounded seed names and required, bounded lifecycle names.
  • Updates unit assertions and adds SQL Server integration coverage for collation behavior, Unicode values, nullability, length limits, indexing, and missing collation.

This edits an existing Alembic revision and requires a maintainer-approved immutability exception before merge.

File Description
tests/​unit/​memory/​test_dataset_lifecycle_migration.py Updates assertions for collation validation.
tests/​integration/​memory/​test_unicode_seed_dataset_names_integration.py Adds execution coverage against disposable local SQL Server.
pyrit/​memory/​alembic/​versions/​a9c3e7f1b205_unicode_seed_dataset_names.py Corrects both COLLATE clauses while preserving column constraints.

Review effort: Balanced

Behnam Ousat and others added 2 commits November 12, 2026 09:41
Remove the redundant collation catalog lookup and the added integration-test file. Keep the ASCII validation and one existing test assertion update; SQL Server execution remains locally verified.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on SQL Server 2025: the QUOTENAME form fails with error 102, and the fixed statement keeps the source collation, nullability and existing non-ASCII values. The allowlist accepts every collation in sys.fn_helpcollations() and rejects non-ASCII or injection-shaped names.

Behnam Ousat and others added 4 commits November 12, 2026 10:27
Check that emitted SQL uses the bare metadata-derived collation without coupling the regression test to the allowlist expression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@behnam-o
Behnam (behnam-o) merged commit bef43bf into microsoft:main Nov 12, 2026
59 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants