Issue
Sentry is reporting "broken repr" as a local variable in my stack trace:
Applies To
- Stack traces
- Customers using the Python SDK
Resolution
Every object in Python can have a __repr__()
function that returns a string representation of that object. This function is called when serializing objects before they are sent to Sentry.
The "broken repr" message appears in Sentry when it cannot obtain a string representation of an object due to an issue with the __repr__()
function. Even if the syntax of the __repr__()
function appears correct, there are a few common reasons it might still fail:
-
Missing Attributes:
The__repr__()
method might fail if it tries to access an attribute that does not exist in the object. Ensure that all attributes used in__repr__()
are present. -
Class Property Issues:
The method might fail if the object does not have a__class__
property. Verify that the object is properly instantiated from a class. -
Context-Specific Failures:
Sometimes, the failure can be context-specific. Testingrepr(someobj)
wheresomeobj
is the same as theself
in the Sentry error can help identify if the issue is with the specific instance or the method itself.
By ensuring that all necessary attributes and properties are present and correctly handled, you can prevent the "broken repr" issue.