Skip to content

Committing a Rolled-Back Object#10899

Open
MarkvanMents wants to merge 6 commits intodevelopmentfrom
MvM-DatabasesAndMemory
Open

Committing a Rolled-Back Object#10899
MarkvanMents wants to merge 6 commits intodevelopmentfrom
MvM-DatabasesAndMemory

Conversation

@MarkvanMents
Copy link
Collaborator

No description provided.

Copy link
Collaborator Author

@MarkvanMents MarkvanMents left a comment

Choose a reason for hiding this comment

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

Thanks for all the comments @basdebakker
I've tried to address them in 89a5f33 - please let me know if it needs more clarification.

{{% /alert %}}
#### What Gets Committed

When you work on an object in memory, Mendix records whether the object has been changed. When you perform a **Commit object(s)** activity, the current value is written to the database and Mendix marks the object as unchanged in memory. This has a couple of consequences that you might not expect:

This comment was marked as resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in ff31fe7


| Option | Behavior |
| --- | --- |
| Rollback (default) | All changes are reverted to the state before the microflow started, the microflow aborts, and a system error message is shown. |
Copy link
Contributor

@lvanengelen-mx lvanengelen-mx Mar 23, 2026

Choose a reason for hiding this comment

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

I think a system error message is only shown if the error is not caught using error handling on a higher level and is allowed to bubble up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in ff31fe7

Copy link
Contributor

@lvanengelen-mx lvanengelen-mx Mar 25, 2026

Choose a reason for hiding this comment

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

Some feedback after our discussion:

All changes are reverted to the state before the microflow started, the microflow aborts,

'the microflow': is it the microflow in which the error handling is defined or the microflow that is called by the Call Microflow action on which error handling is defined.

and a system error message is shown unless custom error handling is added in a microflow which called this one

I would phrase it as cause -> effect, something like: 'if the error is not handled, a system error message is shown'

| Option | Behavior |
| --- | --- |
| Rollback (default) | All changes are reverted to the state before the microflow started, the microflow aborts, and a system error message is shown. |
| Custom with rollback | All changes are reverted to the state before the microflow started, an error flow is followed, and the microflow's subsequent behavior depends on whether the error handling flow ends with an error or end event. |
Copy link
Contributor

Choose a reason for hiding this comment

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

'All changes ... state before the microflow started' might be a bit ambiguous here.

In the following setup (client request triggers MF1, MF1 triggers MF2, MF2 triggers MF3, which fails)

request -> MF1
MF1: Start -> ... database stuff ... -> call MF2 Rollback -> End
MF2: Start -> ... more database stuff ... -> call MF3 Custom with rollback
MF3: FAIL

all database operations in 'database stuff' and 'more database stuff' are reverted. If MF1 did 'call MF2 Custom without rollback' instead, only 'more database stuff' is reverted.

Copy link
Contributor

Choose a reason for hiding this comment

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

If MF1 did 'call MF2 Custom without rollback' instead, only 'more database stuff' is reverted.

But aren't we talking about Custom with rollback here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I just wanted to indicate how the call MF2 error handling configuration influences to which state the database is rolled back. This, to indicate that you do not know to what level the data is rolled back in the case of nested transactions. It could be to the database state at the start of the microflow calling the failing action (i.e. the start of MF2) or a database state at another level entirely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But doesn't it always end up in the state before this MF is called - the error propagation might then change it again - but for an instant when this particular MF errors the rollback will only go as far as the calling microflow and then work out what to do with the error there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I fully understand, probably because I am not 100% sure about what you mean by state. In the following:

request -> MF1
MF1: S -> A1 -> Call MF2 Rollback -> E
MF2: S -> A2 -> Call MF3 Custom with rollback -> E
MF3: S -> FAIL

when the Call MF3 fails, execution continues in its error flow (execution state) while the database resets to the last savepoint, which is all the way to the start of MF1.

So we should probably be careful with the word 'state' as well :-)

1. An error occurs, the microflow ends and data in the database is rolled back to the savepoint.
1. You perform a **Commit object(s)** on the object again, but the changes are not written to the database because:

* The object in memory still has your changes
Copy link
Contributor

@lvanengelen-mx lvanengelen-mx Mar 23, 2026

Choose a reason for hiding this comment

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

Unless any other changes were made after the first commit, I do not think this is correct. As the commit succeeded, the changes were applied to the object in memory and the object does not have changes. It's just that the earlier changes are now the current values. I.e. rolling back this object would keep the same values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the next bullet point covers it? Or combine with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Combined bullets in ff31fe7

Copy link
Contributor

Choose a reason for hiding this comment

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

To me, 'the object in memory still has changes' here can mean two things:

  • the attributes have the same value as those that you set, but the original values are still there as well. I.e. rolling back this object will undo your changes
  • the attributes have the same value as those that you set and the original values are the same. I.e. rolling back this object will keep the same values as the values you set.


#### Committing Non-Persistable Entities

Mendix mimics this behavior for non-persistable entities. Committing a non-persistable entity means that you cannot use a rollback object activity to go back to the previous values, although the rollback error handling in a microflow rolls back to the original values.
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not understand this part. Rollback on NPEs and PEs should work the same. After a commit the original values are replaced with the updated values, so a rollback will revert to the updated values. But that is the same for both NPEs and PEs.

Copy link
Member

Choose a reason for hiding this comment

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

A transaction rollback (which is what "the rollback error handling in a microflow" refers to) will rollback PEs to their original values from before the microflow, regardless of whether they were committed (as in commit object activity, not as in transaction commit).

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand @basdebakker but as far as I know, in general, nothing of the in-memory state of a mendix object is touched on a transaction commit or rollback. The two are independent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we change this - I'm not sure how to make it clearer. I'm trying to say that PEs and NPEs work the same, but obviously I'm not being clear.

Copy link
Member

Choose a reason for hiding this comment

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

What @lvanengelen-mx is saying is just my point (I think). A transaction rollback will rollback any PEs to the state they were in before the transaction started. But it will not affect NPEs. So in that sense they are treated differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bas and I came to the conclusion that we had a misunderstanding on what we meant with PE/NPE: state in memory vs state in the database.

Copy link
Collaborator Author

@MarkvanMents MarkvanMents left a comment

Choose a reason for hiding this comment

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

Thanks for the comprehensive review.
Resolved some of these (I hope) - there are still two discussions outstanding where I'm not sure what best to say.
Can you have another look and see if there are still changes I need to make.
Thanks for all your work so far.

| Option | Behavior |
| --- | --- |
| Rollback (default) | All changes are reverted to the state before the microflow started, the microflow aborts, and a system error message is shown. |
| Custom with rollback | All changes are reverted to the state before the microflow started, an error flow is followed, and the microflow's subsequent behavior depends on whether the error handling flow ends with an error or end event. |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But doesn't it always end up in the state before this MF is called - the error propagation might then change it again - but for an instant when this particular MF errors the rollback will only go as far as the calling microflow and then work out what to do with the error there?

{{% /alert %}}
#### What Gets Committed

When you work on an object in memory, Mendix records whether the object has been changed. When you perform a **Commit object(s)** activity, the current value is written to the database and Mendix marks the object as unchanged in memory. This has a couple of consequences that you might not expect:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in ff31fe7

1. An error occurs, the microflow ends and data in the database is rolled back to the savepoint.
1. You perform a **Commit object(s)** on the object again, but the changes are not written to the database because:

* The object in memory still has your changes
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Combined bullets in ff31fe7


#### Committing Non-Persistable Entities

Mendix mimics this behavior for non-persistable entities. Committing a non-persistable entity means that you cannot use a rollback object activity to go back to the previous values, although the rollback error handling in a microflow rolls back to the original values.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we change this - I'm not sure how to make it clearer. I'm trying to say that PEs and NPEs work the same, but obviously I'm not being clear.


| Option | Behavior |
| --- | --- |
| Rollback (default) | All changes are reverted to the state before the microflow started, the microflow aborts, and a system error message is shown. |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in ff31fe7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants