Skip to content
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

Throw a when two objects represent the same document in a session #601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sebastienros
Copy link
Owner

No description provided.

@sebastienros
Copy link
Owner Author

With the recent changes on identity map, when SaveChangesAsync() is invoked to commit the transaction we clear the IM such that the next queries get refreshed data from the db.

With that change, if we kept a previously loaded object (and potentially modified) but also did a query that was loading the same identity, we could get two objects with different states. This will throw a meaningful exception now.

This happens in OC where the identity stores call SaveChangesAsync after each operation, committing the transaction, where they should do nothing and let auto-flush "flush" the db (without committing the transaction and clearing the IM), or call FlushAsync(). So in a parallel PR I will remove these calls and replaces them with FlushAsync.


if (state.IdentityMap.TryGetEntityById(id, out var _))
{
throw new InvalidOperationException("An object with the same identity is already part of this transaction. Reload it before doing any changes on it.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

How would this code fix the problem we noticed today? Wouldn't this throw a different spin exception but still fails?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, this is not fixing the problem "in OC", there is a PR in OC for that. It's just showing a better message such that if someone missuses yessql they will know.

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