check parents existence first
Merge pull request #4419 from dimagi/parentref

check parents existence first