https://github.com/dimagi/core-hq/pull/972/files#L1R827