[1.6.x] Fixed #21566 -- Fixed AttributeError when using bulk_create with ForeignObject.

Backport of bbc73e6a12 from master.