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

Pickling and unpickling BaseUrlSession will loose base_url #375

Closed
Inokinoki opened this issue Mar 25, 2024 · 1 comment · Fixed by #376
Closed

Pickling and unpickling BaseUrlSession will loose base_url #375

Inokinoki opened this issue Mar 25, 2024 · 1 comment · Fixed by #376

Comments

@Inokinoki
Copy link
Contributor

Inokinoki commented Mar 25, 2024

Pickle and unpickle a BaseUrlSession will result in an empty URL:

>>> from requests_toolbelt.sessions import BaseUrlSession
>>> import pickle
>>> session = BaseUrlSession(base_url="https://www.test.com")             
>>> with open("pickled_session.pkl", "wb") as f:
...     pickle.dump(session, f)
... 
>>> with open("pickled_session.pkl", "rb") as f:
...     s = pickle.load(f)
...   
>>> s.base_url
>>> session.base_url
'https://www.test.com'

In requests, the attributes are handled the in:

    def __getstate__(self):
        state = {attr: getattr(self, attr, None) for attr in self.__attrs__}
        return state

    def __setstate__(self, state):
        for attr, value in state.items():
            setattr(self, attr, value)

I think base_url should also be handled in BaseUrlSession. I can create a PR for this and ask for you review

@sigmavirus24
Copy link
Collaborator

I'll review that for sure

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

Successfully merging a pull request may close this issue.

2 participants