How to program the access to objects of specific document versions

Hi,

for some application I want to access the content of objects valid at specific document versions:

If I write something like

print doc.getObject("XWiki.AnyMyClass").getValue("someKey")

the displayed value of the object will respect the current version of the document, if the document is opened from history.

But if I try something like

testdoc=xwiki.getDocument("anyFullName","4.1")

opening a specific document version testdoc.getObject(…) only return null values although the
target version contains the specified object.

It looks like the api calls

  xwiki.getDocument(DocumentReference reference)
  xwiki.getDocument(DocumentReference reference, String revision)

return Document variables with different features.

The only workaround I see may be doc.getObjectDiff (comparing to version 1.1)
But this I didn’t checked.

Has anyone got any ideas for a better solution? May be I missed something.

Thanks
Norbert

Indeed, I could reproduce. I wasn’t aware of this and it looks like a bug (or a serious limitation) to me.

And the javadoc doesn’t mention anything about not returning xobjects:

    /**
     * Load the document in the provided revision.
     * 
     * @param document the current document
     * @param revision the revision of the document
     * @return the {@link XWikiDocument} instance or null if none existing
     * @throws XWikiException when failing to load the document revision
     */
    XWikiDocument getRevision(XWikiDocument document, String revision) throws XWikiException;

Let’s see what others say, but I’d open a jira issue about it (I couldn’t find one and it’s surprising, I probably haven’t searched well enough).

Sorry - there is no error in the wiki.

It is just a programming error.
The documentation states for xwiki.getDocument different results depending on parameter types:

Document	getDocument​(Document doc, String rev)	
Load a specific revision of a document

Document	getDocument​(String documentReference)	
Loads an Document from the database.

Document	getDocument​(String space, String fullname)	
Loads an Document from the database.

Document	getDocument​(DocumentReference reference)	
Loads a Document from the database.

Document	getDocument​(DocumentReference reference, String revision)	
Load a specific revision of a document

My example code uses a String type first parameter and not a DocumentReference.

The result is a new file with the name of the revision string.
This file does not contain any XObjects of course.

Sorry for the inaccurate reading

Norbert