Fixes NPE when a discarded document is persisted.