Repository navigation
FIX: Correct SQL Server migration collation - #4247
Behnam (behnam-o) merged 7 commits into
Conversation
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>
There was a problem hiding this comment.
🔵 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
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>
Richard Lundeen (richlundeen)
left a comment
There was a problem hiding this comment.
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.
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>
Description
Fix #3920's SQL Server error 102:
COLLATErejectsQUOTENAME-delimited collation names.& $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_immutabilityfails as expected because this fixes an existing revision. No checks disabled or bypassed.