bugsnag / bugsnag-python

Official BugSnag error monitoring and error reporting for django, flask, tornado and other python apps.
https://docs.bugsnag.com/platforms/python/
MIT License
84 stars 42 forks source link

Guard access to `__code__` #387

Closed imjoehaines closed 3 months ago

imjoehaines commented 3 months ago

Goal

We read __code__ when setting a custom delivery object and when sending sessions in order to warn when a custom Delivery implementation doesn't have an options parameter

However, this breaks when using a Mock object as __code__ does not exist, nor can it be mocked

This PR adds a guard before reading __code__ so that we avoid a crash if it does not exist. We don't warn in this case as real delivery implementations should always have __code__ available, so a warning is likely to be just noise when running tests

Testing

Added a unit test using a Mock object for delivery