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

OrderManagement.completeOrder(…) still returns completed Order on failure #409

Closed
Deric-W opened this issue Nov 13, 2022 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@Deric-W
Copy link

Deric-W commented Nov 13, 2022

An Exception is thrown if OrderManagement.completeOrder fails because there is not enough stock to complete the order.
To my surprise is Order.isCompleted() equal to true after the failed call, which is not what I expected it to.
Interestingly, the change seems not to be stored and can be reversed with order = this.orders.get(order.getId()).get();.

Maybe related to #23?

@odrotbohm odrotbohm changed the title OrderManagement.completeOrder modifies Order on failure OrderManagement.completeOrder(…) modifies Order on failure Nov 13, 2022
@odrotbohm odrotbohm self-assigned this Nov 13, 2022
@odrotbohm odrotbohm added type: enhancement Improvements and new features in: documentation Reference documentation, Javadoc, website labels Nov 13, 2022
@odrotbohm odrotbohm added this to the 8.0.1 milestone Nov 13, 2022
@odrotbohm
Copy link
Member

Unfortunately, JPA, the persistence mechanism leaves instances in the state to be modified, even if the transaction rolls back due to an exception. This means, that quite generally, you have to assume entities to be in an undefined state when an exception occurs and reload them through corresponding APIs, just as you already do.

I'll add a note to the Javadoc of OrderManagement.completeOrder(…) to warn about this.

@odrotbohm odrotbohm changed the title OrderManagement.completeOrder(…) modifies Order on failure OrderManagement.completeOrder(…) still returns completed Order on failure Nov 13, 2022
@odrotbohm odrotbohm added type: bug Bugs module: orders Orders and removed type: enhancement Improvements and new features in: documentation Reference documentation, Javadoc, website labels Nov 13, 2022
@odrotbohm
Copy link
Member

I've found a way to work around the problem that's not particularly elegant, but should work for our purposes.

odrotbohm added a commit that referenced this issue Nov 13, 2022
We now properly reset the order's status in case of an exception being thrown from event listeners.
odrotbohm added a commit that referenced this issue Nov 13, 2022
We now properly reset the order's status in case of an exception being thrown from event listeners.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants