-
Notifications
You must be signed in to change notification settings - Fork 936
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
Test ISession.IsDirty() should not trigger cascade saving #1414
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test case.
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GHTODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be GH1413
instead of GHTODO
, here and in other files.
|
||
bool isDirty = false; | ||
Assert.DoesNotThrow(() => isDirty = session.IsDirty(), "ISession.IsDirty() call should not fail for transient many-to-one object referenced in session."); | ||
Assert.IsTrue(isDirty, "ISession.IsDirty() call should return true."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new tests, we favor NUnit constraint model over its classic model, see two models.
@fredericDelaporte Done. I'm not very comfortable with this "constraint model" - so let me know if anything is not right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change.
PR updated (I cleaned up all not related stuff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please modify the test to check that there were no inserts performed (with SqlLogSpy)? It seems that with the current state it does generate IDs but does not actually saves anything to the database.
@hazzik Sorry I won't be able to do any coding in the following week or two. The main point of the test - IsDirty() should not modify nor entities in memory nor DB state. It should be immutable operation. Don't you agree? As @fredericDelaporte already pointed out here:
So this test checks this part - and I think there is no need to do additional checks if SQL is really generated. Let me know if you disagree - I will update tests as you think is right. |
I have added statistics instead, with native generator. See commit details. |
@fredericDelaporte this way this issue becomes a duplicate of NH-2136. Which is closed "By design". The problem is that if we want to fix this issue - we need completely rewrite IsDirty. |
The point is, was it really reasonable to close this as "by design" without more actions? I do not think so. The bare minimum would be to document the possible side effects of Currently it just states:
So a method explicitly documented as allowing to check if some SQL may be triggered by another operation may itself triggers some SQL without giving any clue about that... Quite unexpected. And it causes |
I have checked the Hibernate implementation, it is still the same than NHibernate on this point.
If it was about rewriting all the |
Having looked a bit more into it, it would require a lot of changes in the cascading logic for allowing a "cascade simulation" just telling whether a save would be done or not. So I think we should likely just document the potential side effects of |
If I try to go this way:
Will you consider it (I suspect it will end up in copy-paste from flush routine)? Current implementation seems like not very useful as identity generators are commonly used (at least in projects where I was involved). And processing all the objects in session - doesn't look as effective solution. |
The dirty checking mechanism is injectable at many levels, including for the global dirty check on the session. You can change the default isDirty event handler for the session by setting another one, implementing |
This can "easily" be fixed by enabling this branch of code: nhibernate-core/src/NHibernate/Event/Default/AbstractSaveEventListener.cs Lines 256 to 266 in 0b66742
Unfortunately due to "NH Different behavior (shouldDelayIdentityInserts=false anyway)" it never executes. Hope this helps. |
I think that proper dirty check shouldn't call |
It does not. We need the other means to enable delayed inserts for the dirty checks. |
Rebased, squashed, commit reworded, test is marked as known bug. |
Added failing test cases for #1413.