Skip to content

NH-3912 Oracle IBatcher impl instance is not reusable after failed operation. #513

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
Nov 21, 2016

Conversation

waynesayonara
Copy link

@waynesayonara waynesayonara commented Oct 19, 2016

Batch operations with the same IBatcher instance fail on expected rows count after single failed operation.
Also, passed DbException message for oracle batcher to outer message.

This issue regards OracleDataClientBatchingBatcher. It seems that in the scenario where two batch commands are performed using the same instance of OracleDataClientBatchingBatcher, second batch command will nearly always fail on expected rows count assert. This will only happen if first batch command failed before the second one (any error will do). The reason is that internal counter _totalExpectedRowsAffected isn't reset after first failed batch command.
Example:
BATCH1:
_totalExpectedRowsAffected += 1 (now 1, was 0)
Insert into table and fail on unique constaint violation for instance
_totalExpectedRowsAffected is not reset.
BATCH2:
_totalExpectedRowsAffected += 1 (now 2, was 1)
Insert into table and succeed
Assert Expectations.VerifyOutcomeBatched fails because _totalExpectedRowsAffected and only one row was actually affected.
Every consecutive batch command will also fail.

Pull requests contains following changes:

  • _totalExpectedRowsAffected is reset now regardless of the batch query execution outcome (in finally block)
  • DbException.Message is passed to the AdoExceptionHelper, so diagnostic information will be included in the exception propagated to user code.

@hazzik
Copy link
Member

hazzik commented Oct 26, 2016

@waynesayonara I've restricted tests to the Oracle specific dialects only, fixed the indents. So I had to force push your changes with rebase on current master.

@waynesayonara
Copy link
Author

@hazzik Do I need to fix unsuccessful checks at this point (3 of them) or you will merge it anyway?
PS Sorry about indents.

@hazzik
Copy link
Member

hazzik commented Oct 27, 2016

They are unrelated, these tests are fluffy.

catch (DbException e)
{
// Message from DbException could be useful
var additionalMessage = string.IsNullOrEmpty(e.Message) ? "." : string.Concat(": ", e.Message);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why this is required. I've not run it, but looking at the code is seems the exception e should eventually end up as inner exception inside the "converted" exception and the message can and should be read from that.

Copy link
Member

@hazzik hazzik Nov 20, 2016

Choose a reason for hiding this comment

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

@oskarb this is how it was already implemeted. The real change here is additional try-finally around the execution block. So zeroing of varaibles go to finally.

I think it shall go to 4.1

Copy link
Member

Choose a reason for hiding this comment

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

additionalMessage in string.Format("could not execute batch command{0}", additionalMessage) is new. That's what I'm referring to.

Copy link
Member

Choose a reason for hiding this comment

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

In MinimalSQLExceptionConverter and SQLStateConverter the actual exception will end up as an inner exception of GenericADOException. So, I think it's fine. Or, we can amend the PR to remove this change.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's my point, it's already there. Based on the comment in the PR and also in the code, the additionalMessage seems to have been added based on the idea that without it, the message from the original exception was somehow lost. As far as I can tell, the inner exception will be there as expected and then for anything that does log the exception chain properly, this will just be unfortunate duplication. t's not a big issue and I don't care too much either way, but I think it should be removed.

@oskarb oskarb added this to the 5.0.0 milestone Nov 20, 2016
@hazzik hazzik force-pushed the NH3912 branch 2 times, most recently from 3f18333 to 87b8d9c Compare November 20, 2016 21:39
…pected rows count after single failed operation.
@hazzik
Copy link
Member

hazzik commented Nov 20, 2016

@oskarb I've changed the PR

@oskarb oskarb modified the milestones: 4.1.0, 5.0.0 Nov 20, 2016
@oskarb
Copy link
Member

oskarb commented Nov 20, 2016

Sure we can have this in 4.1.

@oskarb oskarb merged commit 94f276a into nhibernate:master Nov 21, 2016
@hazzik
Copy link
Member

hazzik commented Dec 22, 2016

I've missed one point on this pull request...

The user shall never reuse session after an exception. Ever.

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