Removing pages with JsonContentProperties fails: “deleted object would be re-saved by cascade”

Hey,

My plugin is storing JsonContentProperties on a page using the ContentPropertyService. When I try to delete the page through the Confluence UI (either by removing the space, or by deleting it and then purging the trash), I keep getting two different exceptions (sometimes one, sometimes the other) on Confluence 6.7.0.

The first one says: “java.lang.RuntimeException: deleted object would be re-saved by cascade (remove deleted object from associations): [com.atlassian.confluence.pages.Page#720965]. Listener: com.atlassian.confluence.core.listeners.BundledContentSpaceRemovalListener event: com.atlassian.confluence.event.events.space.SpaceWillRemoveEvent”. (Full stack trace here: https://pastebin.com/wHj7fr4A)

The second one says: “org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [fkwjyn6091q3l1gl7bh143ma2a]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement” (full stack trace here: https://pastebin.com/66jywFcV)

The first one looks like Confluence is trying to get the list of page descendants in order to delete the page tree. Then Hibernate wants to flush the current transaction before searching the database for descendants. For some reason, when flushing the transaction, it attempts to save my content property again and fails because the page that it’s referencing as its container is marked as deleted (no idea why the page is marked as deleted already at this point).

The second one looks like Confluence is trying to delete the page before deleting the content property attached to it. (The foreign key constraint is the one that links the “pageid” in the “content” table to the “contentid” in the same table.)

The code that creates the content property looks like this:

JsonContentProperty newProperty = JsonContentProperty.builder()
    .content(page)
    .key(propertyKey)
    .value(new JsonString(jsonString))
    .version(Version.builder().number(1).build())
    .build();

contentPropertyService.create(newProperty);

I don’t feel like there is a lot to do wrong when creating a content property, so I have no clue what could be going wrong. I have already spent two days digging through the Confluence code and Hibernate stack traces, but I’m totally lost and don’t understand what’s going on.

It also looks like there is no event when a page is purged from the trash, so I guess I cannot even manually delete the content property in that moment.

Does anyone have a clue how I could solve the problem?

2 Likes

I have created a bug report for this.

As a workaround, the content property can be removed before removing the page/space.

I also discovered that when running pageManager.deepCopyPage() after creating the content property, the issue doesn’t come up. I couldn’t figure out so far why.

1 Like