Skip to content

Targeted fix for #35162 - Regression from EF Core 8 to 9: MigrationBuilder.DropTable Causes Issues with Subsequent Table Recreation #35764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Mar 11, 2025

Problem was that in 9.0 we changed how we process temporal tables, tracking the temporal table information as we process migrations. However, we didn't take into account the cases where users would manually modify their migrations, or squash multiple migrations together, resulting in corrupted dictionary access for cases where a table was deleted and created in the same migration. This fix just makes the temporal information map handling more robust, so those errors don't happen anymore. There is a broader issue with temporal tables but those will be addressed in a different PR.

Fixes #35162

@maumar maumar requested a review from a team as a code owner March 11, 2025 11:06
@maumar maumar requested review from Copilot and a team and removed request for a team March 11, 2025 11:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR targets regression issue #35162 by making the temporal table information map handling more robust during migration operations. Key changes include:

  • Adding new composite tests for various scenarios, including dropping/creating and renaming tables.
  • Introducing a new TestComposite helper method for testing multiple model transitions.
  • Updating the SQL Server migrations SQL generator to improve temporal table information handling.

Reviewed Changes

File Description
test/EFCore.Relational.Specification.Tests/Migrations/MigrationsTestBase.cs Added multiple composite tests and the TestComposite helper to validate complex migration scenarios.
test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs Added corresponding functional tests with SQL assertions for the new migration operations.
src/EFCore.SqlServer/Migrations/SqlServerMigrationsSqlGenerator.cs Refactored the temporal information mapping logic to handle table renaming and creation more robustly.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@maumar maumar force-pushed the targetedfix35162 branch 2 times, most recently from 425d14c to c96f8a2 Compare March 11, 2025 17:28
@maumar maumar force-pushed the targetedfix35162 branch from c96f8a2 to 35733e2 Compare March 12, 2025 05:08
…ilder.DropTable Causes Issues with Subsequent Table Recreation

Problem was that in 9.0 we changed how we process temporal tables, tracking the temporal table information as we process migrations. However, we didn't take into account the cases where users would manually modify their migrations, or squash multiple migrations together, resulting in corrupted dictionary access for cases where a table was deleted and created in the same migration.
This fix just makes the temporal information map handling more robust, so those errors don't happen anymore. There is a broader issue with temporal tables but those will be addressed in a different PR.

Fixes #35162
@maumar maumar force-pushed the targetedfix35162 branch from 35733e2 to d5fc85c Compare March 12, 2025 05:10
maumar added a commit that referenced this pull request Mar 12, 2025
…Table Causes Issues with Subsequent Table Recreation

Port of #35764

Fixes #35162

Description
Problem was that in 9.0 we changed how we process temporal tables, tracking the temporal table information as we process migrations. However, we didn't take into account the cases where users would manually modify their migrations, or squash multiple migrations together, resulting in corrupted dictionary access for cases where a table was deleted and created in the same migration. This fix just makes the temporal information map handling more robust, so those errors don't happen anymore. There is a broader issue with temporal tables but those will be addressed in a different PR.

Customer impact
Some manually modified/squashed migrations no longer work when they are being applied, throwing an unhelpful exception (The given key '...' was not present in the dictionary.'). No good workaround apart from breaking the migrations apart.

How found
Reported by multiple customers on 9.

Regression
Yes.

Testing
Added infra to test these types of scenarios (containing intermediate migration state), added multiple tests both for regular and temporal tables.

Risk
Low - Very targeted fix, accessing the temporal information dictionary in a more robust way. No quirk, since migrations are design time, so hard to set switches for them.
@maumar maumar merged commit c756434 into main Mar 12, 2025
7 checks passed
@maumar maumar deleted the targetedfix35162 branch March 12, 2025 06:18
maumar added a commit that referenced this pull request Mar 12, 2025
…Table Causes Issues with Subsequent Table Recreation

Port of #35764

Fixes #35162

Description
Problem was that in 9.0 we changed how we process temporal tables, tracking the temporal table information as we process migrations. However, we didn't take into account the cases where users would manually modify their migrations, or squash multiple migrations together, resulting in corrupted dictionary access for cases where a table was deleted and created in the same migration. This fix just makes the temporal information map handling more robust, so those errors don't happen anymore. There is a broader issue with temporal tables but those will be addressed in a different PR.

Customer impact
Some manually modified/squashed migrations no longer work when they are being applied, throwing an unhelpful exception (The given key '...' was not present in the dictionary.'). No good workaround apart from breaking the migrations apart.

How found
Reported by multiple customers on 9.

Regression
Yes.

Testing
Added infra to test these types of scenarios (containing intermediate migration state), added multiple tests both for regular and temporal tables.

Risk
Low - Very targeted fix, accessing the temporal information dictionary in a more robust way. No quirk, since migrations are design time, so hard to set switches for them.
maumar added a commit that referenced this pull request Mar 13, 2025
…Table Causes Issues with Subsequent Table Recreation (#35776)

Port of #35764

Fixes #35162

Description
Problem was that in 9.0 we changed how we process temporal tables, tracking the temporal table information as we process migrations. However, we didn't take into account the cases where users would manually modify their migrations, or squash multiple migrations together, resulting in corrupted dictionary access for cases where a table was deleted and created in the same migration. This fix just makes the temporal information map handling more robust, so those errors don't happen anymore. There is a broader issue with temporal tables but those will be addressed in a different PR.

Customer impact
Some manually modified/squashed migrations no longer work when they are being applied, throwing an unhelpful exception (The given key '...' was not present in the dictionary.'). No good workaround apart from breaking the migrations apart.

How found
Reported by multiple customers on 9.

Regression
Yes.

Testing
Added infra to test these types of scenarios (containing intermediate migration state), added multiple tests both for regular and temporal tables.

Risk
Low - Very targeted fix, accessing the temporal information dictionary in a more robust way. No quirk, since migrations are design time, so hard to set switches for them.
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.

Regression from EF Core 8 to 9: MigrationBuilder.DropTable Causes Issues with Subsequent Table Recreation
2 participants