An error occurred while searching for spaces in Space Directory after Importing a Space Backup into Confluence

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary 

The message "An error occurred while searching for spaces." is thrown when accessing the space directory after a space import is run.

Environment

  • Confluence Server or Data Center
  • A space was recently imported

Diagnosis

Reviewing <home-directory>/logs/atlassian-confluence.log an error like such will be displayed:

(lightbulb)Note "spacedirectory/view.action" in the referer shows the space directory is being loaded

atlassian-confluence.log
2020-08-21 13:48:58,780 ERROR [http-nio-6702-exec-1] [common.error.jersey.ThrowableExceptionMapper] toResponse Uncaught exception thrown by REST service: The body of this ContentEntityObject ('') was 'BodyType:XHTML' but was expected to be 'BodyType:WIKI'
 -- referer: http://localhost:6702/c702/spacedirectory/view.action | url: /c702/rest/spacedirectory/1/search | traceId: 10fc4d197ff99f11 | userName: admin
java.lang.UnsupportedOperationException: The body of this ContentEntityObject ('') was 'BodyType:XHTML' but was expected to be 'BodyType:WIKI'
	at com.atlassian.confluence.core.ContentEntityObject.getBodyContent(ContentEntityObject.java:275)
	at com.atlassian.confluence.core.ContentEntityObject.getBodyAsString(ContentEntityObject.java:317)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:84)
	at com.atlassian.hibernate.adapter.proxy.JavassistLazyInitializer_ImplementV2Proxy.invoke(JavassistLazyInitializer_ImplementV2Proxy.java:68)
	at com.atlassian.confluence.spaces.SpaceDescription_$$_jvsta6_15.getBodyAsString(SpaceDescription_$$_jvsta6_15.java)
	at com.atlassian.confluence.plugins.spacedirectory.rest.DefaultSpaceDirectoryEntityBuilder.build(DefaultSpaceDirectoryEntityBuilder.java:84)
	at com.atlassian.confluence.plugins.spacedirectory.rest.SpaceDirectoryResource.doSearch(SpaceDirectoryResource.java:94)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.atlassian.plugins.rest.common.interceptor.impl.Dis
        ....

Cause

The spacedescription from the imported space has a differing bodytypeid in the bodycontent table than the existing spaces.

When a page has multiple bodytypeid ids in its bodycontent, Confluence is unable to render the page.

Solution

Always backup your data before performing any modifications to the database.

  1.  Stop Confluence
  2. (warning) Backup Confluence and the database. 
  3. Run the following query

    UPDATE bodycontent SET bodytypeid = 0 WHERE contentid in
    (SELECT DISTINCT content.contentid FROM content 
    INNER JOIN bodycontent on content.contentid = bodycontent.contentid
    where contenttype = 'SPACEDESCRIPTION' and bodytypeid != 0);
  4. Clear the plugin cache

  5. Rebuild the Content Indexes From Scratch

  6. Start Confluence 


Last modified on Oct 6, 2020

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.