Backport object take

Backports gh-3002, the test commits are unfortunately not clean backports (and the first one extra), because the tests did not exist in 1.7. (and also because I did not separate the tests in gh-3002 as I thought, so it is not possible without doing two non-cherry-pick commits). So I could make these three commits, but then the one code commits is not a clean cherry-pick. Ah well...