-
Notifications
You must be signed in to change notification settings - Fork 32
Ensure that we delist the trigger session on exception in the BeforeSave cycle #169
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
Conversation
…ave cycle. Closes #168
src/EntityFrameworkCore.Triggered/Internal/TriggerSessionSaveChangesInterceptor.cs
Show resolved
Hide resolved
|
I've done some testing after applying these changes manually to the code I've been using and have encountered a different issue. We have an integration test: The save changes fires a before save trigger: Which eventually thows a NotImplementedException: This delists the session using the code in the When the second insert fires, the If I comment out the |
|
Changed the test to use a different payment method and amount The second |
|
I've added some additional integration tests to see if I could reproduce (which I was not), here: https://github.com/koenbeuk/EntityFrameworkCore.Triggered/blob/issue-168/test/EntityFrameworkCore.Triggered.IntegrationTests/TriggerExceptions/ExceptionTestScenario.cs In your shared code, you do reuse the db instance between the 2 calls. Could the exception be due to the db instance still holding on on earlier data (generated during the first call)? Keep in mind that throwing an exception in a BeforeSave trigger will not reset the state of the DbContext instance, e.g. var entity = new Entity();
db.Add(entity);
try {
db.SaveChanges(); // Assume that this throws in a BeforeSaveTrigger
}
catch (Exception ex) { ... }
Console.WriteLine(db.Entry(entity).State); // Prints: AddedAny subsequent call to SaveChanges will try and insert this entity again and rerun all the triggers |
|
Good point. Let me refactor it a bit and retest |
|
You're right - the object had the same hash code in the second call. I will run the tests today (and test #156) and let you know. Appreciate your work 💯 |
|
Keep me posted, I've hidden the 3.2.2 release on nuget for now. Just in case there is a regression here |
|
@koenbeuk I have tried to reproduce the issue using the new version and have not been able to. I've not noticed any other side effects so I believe the fix is good. |


Closes #168