RavenDB delete document not working

205 views
Skip to first unread message

maria abreu

unread,
Jul 30, 2018, 9:52:08 AM7/30/18
to RavenDB - 2nd generation document database
we are trying to delete several documents, after the line "session.DeleteByID();" if we check the RavenDB database the document is deleted but after the line session.SaveChanges(); some of the documents are recreated. There is no errors or exceptions, we enable logging with level Trace to try to understand what was going on but there is nothing there related to this.

public void Handle(DeleteBatchOfWorkflowsCommand message)
            {
                _logger.Info("Deleting batch of {0} workflows for {1} {2}", message.Workflows.Count, message.AssociationId, message.InitiativeId);

                EndpointRegistry.MakeContainerClientSpecific(_container, message.AssociationId);
                using (var session = _container.GetInstance<ITenantDocumentSession>())
                {
                    var workflows = session.Load<Workflow.Workflow>(message.Workflows);

                    foreach (var workflow in workflows)
                    {
                        if (workflow == null)
                        {
                            _logger.Info("Skipping, workflow has not been created yet");
                        }
                        else
                        {
                            _logger.Info("Deleting workflow and tasks for {0}", workflow.Id);
                            session.DeleteById(workflow.Id);
                        }
                    }

                    session.SaveChanges();
                }
            }

DeleteById implementation

public void DeleteById(string key, Guid? eTag = null)
{
                _inner.Advanced.DocumentStore.DatabaseCommands.ForDatabase(_databaseName).Delete(key, eTag); 
}
Is there a why we can figure out what is going on ?? Server Build #35215 Client Build #35215

Oren Eini (Ayende Rahien)

unread,
Jul 31, 2018, 1:54:19 AM7/31/18
to ravendb
Your DeleteById is NOT actually using the session.
It is using a separate command, which is not a good idea.
Is there any reason why you aren't calling session.Delete() ? 

What is happening is that you are likely modifying (through the load process) the documents, since you delete them behind the session's back, they are saved, re-creating the documents.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

maria abreu

unread,
Aug 1, 2018, 4:13:20 PM8/1/18
to RavenDB - 2nd generation document database
Thank you for the information Oren, I changed the delete line to use "session.Delete(workflow.Id);" and I got the following exception 

2018-07-31 16:35:54,221 [14] INFO  NServiceBus.Unicast.Transport.TransportReceiver [(null)] - Failed to process message
System.InvalidOperationException: Can't delete changed entity using identifier. Use Delete<T>(T entity) instead.
   at Raven.Client.Document.InMemoryDocumentSessionOperations.Delete(String id)
   at Daxko.Relate.WorkflowEndpoint.DeleteBatchOfWorkflowsHandler.Handle(DeleteBatchOfWorkflowsCommand message) in e:\Jenkins\jobs\relate-build-integration\workspace\src\WorkflowEndpoint\DeleteBatchOfWorkflowsHandler.cs:line 43
   at NServiceBus.Unicast.MessageHandlerRegistry.Invoke(Object handler, Object message, Dictionary`2 dictionary)

I then changed it to use the entity "session.Delete(workflow)" and it worked, so I wonder if that was what was happening when using the other delete "_inner.Advanced.DocumentStore.DatabaseCommands.ForDatabase(_databaseName).Delete(key, eTag);" and the exception was just getting swallow up somewhere.
It's working now so Thank you!!.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Aug 1, 2018, 4:28:05 PM8/1/18
to ravendb
There was no exception in that case. this was sent to the server _separate from the session_, it was never involved.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages