The commands are getting executed backwards, with Delete and then Upsert. This is a regression in 1.2.5, I believe tied to ff222c0c4a5ef5823a862a977eb7d9cc90890d51
Failing test coming...
@ericgreenmix I'm not sure I'm buying that this is a bug. It's a pretty odd usage to me.
This happens quite a bit in our application when doing projection rebuilds.
It is odd usage in just a normal case, like the simplified unit test. However when you get into projection rebuilds it, that is a key feature we need.
Why is that? Why would you be both deleting and upserting the same document in the same unit of work?
When doing a projection rebuild using the Async Daemon, the Daemon handles calling SaveChanges. So if it has a stream of events coming in that update a document and then delete it later in the event stream, that causes the issue.
When rebuilding a projection, the entire stream of events for a given aggregate is ran through in the same unit of work. Any aggregate that is ever deleted will have an upsert and deletion in the same UoW in that case.
Pfft, okay. I'm going to address this by making Marten perform the operations in a unit of work in the same order that they were registered w/ the session. Automatic dirty checking actions will be a little flaky with that, but we'll cross that bridge later if it's ever a problem.
Most helpful comment
Pfft, okay. I'm going to address this by making Marten perform the operations in a unit of work in the same order that they were registered w/ the session. Automatic dirty checking actions will be a little flaky with that, but we'll cross that bridge later if it's ever a problem.