Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention pickling in the docs for creating custom Transport Adapters #6255

Open
izabelakowal opened this issue Oct 8, 2022 · 0 comments
Open

Comments

@izabelakowal
Copy link

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant