#1730: Fix error when ctx is not the document.