Skip to content

IAsyncDocumentSession..Advanced.ExistsAsync() returns false if IDocumentStore.OnBeforeDelete throws an exception #12398

Description

@AKlaus

Steps to reproduce:

  1. Setup throwing an exception in IDocumentStore.OnBeforeDelete, e.g. store.OnBeforeDelete += (_, _) => throw new Exception();
  2. Attempt to delete an existing record, e.g. by calling DbSession.Delete("Tickets/1-A")
  3. The record in the DB remains untouched thanks to the exception in the OnBeforeDelete
  4. However, await DbSession.Advanced.ExistsAsync("Tickets/1-A")would return false.
  5. Though, if call DbSession.Advanced.Clear() first then ExistsAsync would return true.

See a relevant test in the YABT project.

Activity

  1. ayende commented on Jun 17, 2021

    @ayende
    Member

    Any exception that is thrown by the session would effectively invalidate it, note.
    What actually happens here is that we first record that we intend to remove the document, even though the exception "failed" the operation. At this point, you cannot assume anything about the state of the session.

    To do otherwise would cause us to have to be very careful and would still leave you with complicated scenarios in the case of server side failure.

    ExistsAsync checks first that the document was registered for removal, and it wasn't removed when the exception happened.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions