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

Fix EHR sql server error #5123

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions query/src/org/labkey/query/controllers/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4548,12 +4548,16 @@ protected JSONObject executeJson(JSONObject json, CommandType commandType, boole
{
if (behaviorType != null && behaviorType != AuditBehaviorType.NONE)
{
if (transaction.getAuditEvent() != null)
auditEvent = transaction.getAuditEvent();
DbScope.Transaction auditTransaction = transacted ? transaction : table.getSchema().getScope().getCurrentTransaction();
if (auditTransaction == null)
auditTransaction = transaction;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this. If transacted is true, we use the ensured transaction from the try block and if it's false we get the transaction from the table schema. Presumably if it's transacted, these are the same thing. If there is no transaction on the table schema, we use the NO_OP_TRANSACTION. So could this be
`

Suggested change
auditTransaction = transaction;
DbScope.Transaction auditTransaction = table.getSchema().getScope().getCurrentTransaction();
if (auditTransaction == null)
auditTransaction = NO_OP_TRANSACTION;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've modified the logic a little bit more to only get scope transaction when the outer caller is indeed transacted.


if (auditTransaction.getAuditEvent() != null)
auditEvent = auditTransaction.getAuditEvent();
else
{
auditEvent = AbstractQueryUpdateService.createTransactionAuditEvent(container, commandType.getAuditAction());
AbstractQueryUpdateService.addTransactionAuditEvent(transaction, getUser(), auditEvent);
AbstractQueryUpdateService.addTransactionAuditEvent(auditTransaction, getUser(), auditEvent);
}
}

Expand Down Expand Up @@ -4976,7 +4980,7 @@ else if (scope != tableInfo.getSchema().getScope())
}
commandObject.put("extraContext", commandExtraContext);

JSONObject commandResponse = executeJson(commandObject, command, transacted, errors);
JSONObject commandResponse = executeJson(commandObject, command, !transacted, errors);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't quite get why this got switched to !transacted. This says if it's not transacted we'll allow transaction if the JSON property is true, but if it is transacted here and that property is true, we don't allow transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has been like this for 12 years. I think it got flipped because it was trying to avoid nested transaction and have the outer transaction used only. Attempt to reverse is resulted in sql server transaction already rolled back error.

// Bail out immediately if we're going to return a failure-type response message
if (commandResponse == null || (errors.hasErrors() && !isSuccessOnValidationError()))
return null;
Expand Down