rbarrois/factory_boy — pull request #129 by anentropic (2014-02-03 14:27:34+00:00)
Title: Make safe repr more safe

`_safe_repr` is called by debug logging code in factoryboy. It seems to me it'd be ideal not to get errors from this part of the code... yes if `repr(obj)` fails you _may_ have a problem with your `obj`... but I'd rather catch that in the actual tests rather than raised due to an internal feature of factoryboy.

A concrete example: trying to create a Django model instance with a fake id for a foreign key relation (rather than using SubFactory and creating the related instance as well)... it would work except `repr(obj)` calls the models `__unicode__` method, which in my case looked at the foreign key and failed, raising a `DoesNotExist` exception.

I think it'd be okay to return the `'bad_repr object'` string for _any_ exception raised.