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
Fixed #29186 -- Fixed pickling HttpRequest and subclasses. #15937
Conversation
@Anv3sh Do you have time to keep working on this? |
Yes I'm working on it. non_picklable_attrs = frozenset(
[
"resolver_match",
"environ",
"META",
"_stream",
]
) Couple of things that I'm confused with is that if we keep the The def __getstate__(self):
obj_dict = self.__dict__.copy()
for attr in self.non_picklable_attrs:
if attr in obj_dict:
del obj_dict[attr]
return obj_dict |
The first question is: Is the |
Got it 👍🏻. As far as I tested the |
@felixxm overrided the def test_pickle_request(self):
request = HttpRequest()
request.method = "GET"
request.COOKIES = {"post-key": "post-value"}
dump = pickle.dumps(request)
request_from_pickle = pickle.loads(dump)
self.assertEqual(repr(request), repr(request_from_pickle)) I found out that the |
@Anv3sh Please add tests. |
So, again, Can you add a test that crashes when |
Ok I will add the test case and remove the |
Added the test for request pickling and sorry for the linting errors missed checking for them. |
Added the |
@felixxm added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Anv3sh Thanks 👍
This patch should allow for removing asgi_request
and wsgi_request
from HttpResponse.non_picklable_attrs
.
@felixxm committed the requested changes don't know why one of the checks failed. |
b009251
to
4ec4640
Compare
4ec4640
to
6220c44
Compare
@Anv3sh Thanks 👍 We don't need more tests because tests added in d7f5bfd will check that
Don't worry this test is flaky. |
Hi @felixxm, will this fix be back-ported to older versions? if so, any timeline? |
nvm, just read the doc |
I don't really understand what the purpose of this change was, but it broke code in Django 4.2 that tries to "clone" and override requests using Something like this was working before:
|
@salomvary Thanks for the report.
It worked only because
Please create a new ticket in Trac and follow our bug reporting guidelines. All bugfixes require an accepted ticket. |
Thanks for the quick response!
I don't see why shallow copying a For me it sounds like this was a change that was necessary for |
Some attributes of |
Should I create the required ticket?? 😄 |
Introduced
DjangoSocketHandler
class to handle socket logging which simply removes all the non-picklable attributes from the request object.