You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While subclassing HTTPAdapter as well as Session the class variable __attrs__ needs to be appended with any custom instance variables. Otherwise, the instance breaks during pickling, which can happen in many different scenarios - for example, during Django's setUpTestData deep copying/in-memory data isolation. I think it would be nice if this is mentioned in the documentation.
There's a classic example of a custom adapter for setting a timeout value that is mentioned in multiple blog posts. Unfortunately, all of these examples are essentially broken because of a lack of information about pickling and __attrs__ class variable.
And yet the pattern of overriding __attrs__ exists in many open source libs, for example:
If this pattern is so commonly used and needed, it might be a good idea to add it to the docs. Again, this is because so many people can stumble upon this issue.
The text was updated successfully, but these errors were encountered:
While subclassing
HTTPAdapter
as well asSession
the class variable__attrs__
needs to be appended with any custom instance variables. Otherwise, the instance breaks during pickling, which can happen in many different scenarios - for example, during Django'ssetUpTestData
deep copying/in-memory data isolation. I think it would be nice if this is mentioned in the documentation.There's a classic example of a custom adapter for setting a timeout value that is mentioned in multiple blog posts. Unfortunately, all of these examples are essentially broken because of a lack of information about pickling and
__attrs__
class variable.And yet the pattern of overriding
__attrs__
exists in many open source libs, for example:https://github.com/requests/toolbelt/blob/master/requests_toolbelt/adapters/ssl.py#L46
https://github.com/docker/docker-py/blob/main/docker/transport/unixconn.py#L57
If this pattern is so commonly used and needed, it might be a good idea to add it to the docs. Again, this is because so many people can stumble upon this issue.
The text was updated successfully, but these errors were encountered: