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

What should happen when attaching an inconsistent entity? #1246

Closed
ajcvickers opened this issue Dec 8, 2014 · 1 comment
Closed

What should happen when attaching an inconsistent entity? #1246

ajcvickers opened this issue Dec 8, 2014 · 1 comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown
Milestone

Comments

@ajcvickers
Copy link
Member

Consider calling Attach, AttachGraph, or setting the state of an entity to Unchanged. The expectation is that the state of the entity will be Unchanged. However, what if the entity references a principal with a PK that doesn't match the FK in the new entity? We discussed this at length when implementing FK support in the old stack and came to the conclusion that we should throw a constraint exception. One of the alternatives was to fixup the FK and mark the entity as Modified. This is currently the behavior in the new stack for AttachGraph, and may not be totally unreasonable given:

  • This shouldn't happen if the graph is really being attached after being disconnected
  • If the graph wasn't disconnected but was instead just constructed, then fixing up the FK may be the correct thing to do anyway
  • The exception might help you find a bug in your code, but otherwise doesn't seem useful.
@rowanmiller rowanmiller added this to the 7.0.0 milestone Dec 8, 2014
ajcvickers added a commit that referenced this issue Dec 10, 2014
Issue #1247. Calling Remove for and Added entity still resulted in the Detached (Unknown) state, but now setting the state to Deleted does result in the Deleted state.

The only place where setting a state may result in a different state is when attempting to set to Unchanged with an FK that is inconsistent. See #1246.
@ajcvickers
Copy link
Member Author

Current decision on this is that in the case where the FK is not consistent with the graph it is acceptable to change the FK and mark the entity as modified. It isn't really Attaching that is doing this, but the associated fixup that happens, and this is what fixup is supposed to do.

ajcvickers added a commit that referenced this issue Dec 10, 2014
Issue #1247. Calling Remove for and Added entity still resulted in the Detached (Unknown) state, but now setting the state to Deleted does result in the Deleted state.

The only place where setting a state may result in a different state is when attempting to set to Unchanged with an FK that is inconsistent. See #1246.
@ajcvickers ajcvickers modified the milestones: 7.0.0-rc1, 7.0.0 Dec 10, 2014
ajcvickers added a commit that referenced this issue Jul 10, 2019
Fixes #15819

We had previously decided in #1246 on a behavior for resolving this, but that behavior results in not tracking the graph passed to us. On reflection, that decision was likely wrong, so reverting it here to avoid discarding entities in the graph.
ajcvickers added a commit that referenced this issue Jul 11, 2019
Fixes #15819

We had previously decided in #1246 on a behavior for resolving this, but that behavior results in not tracking the graph passed to us. On reflection, that decision was likely wrong, so reverting it here to avoid discarding entities in the graph.
ajcvickers added a commit that referenced this issue Jul 11, 2019
Fixes #15819

We had previously decided in #1246 on a behavior for resolving this, but that behavior results in not tracking the graph passed to us. On reflection, that decision was likely wrong, so reverting it here to avoid discarding entities in the graph.
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.0.0-beta3, 1.0.0 Oct 15, 2022
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown
Projects
None yet
Development

No branches or pull requests

2 participants