Backports #3397 to 3.1.0-stable branch

We got hit by this as well in an embedded document `where`.