Fix TypeError when generating diff for an object with circular structure

Fixes #1179