#34484: HttpRequest.__deepcopy__ doesn't deepcopy attributes
---------------------------------+--------------------------------------
     Reporter:  Adam Johnson     |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  HTTP handling    |                  Version:  4.2
     Severity:  Release blocker  |               Resolution:
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Description changed by Adam Johnson:

Old description:

> Regression in Django 4.2. Deepcopying a HttpRequest no longer deepcopies
> its attributes, including attached ones like `session`.
>
> Leads to test pollution where a request is created in setUpTestData, for
> example:
>
> {{{
> from django.test import TestCase
> from django.test import RequestFactory
>

> class ExampleTests(TestCase):
>     @classmethod
>     def setUpTestData(cls):
>         cls.request = RequestFactory().get("/")
>         cls.request.session = {}
>
>     def test_adding(self):
>         self.request.session["foo"] = 1
>         self.assertEqual(self.request.session, {"foo": 1})
>
>     def test_looking(self):
>         self.assertEqual(self.request.session, {})
> }}}
>
> (Simplified from a real test suite.)
>
> Bisected to #29186 / 6220c445c40a6a7f4d442de8bde2628346153963, using
> these commands to run the above test case:
>
> {{{
> git bisect start facc153af7 ff8e5eacda
> git bisect run sh -c 'cd tests && ./runtests.py test_regression -v 2'
> }}}
>
> I see #34482 was also just opened as a regression from that same ticket.

New description:

 Regression in Django 4.2. Deepcopying a HttpRequest no longer deepcopies
 its attributes, including attached ones like `session`.

 Leads to test pollution where a request is created in setUpTestData, for
 example:

 {{{
 from django.test import TestCase
 from django.test import RequestFactory


 class ExampleTests(TestCase):
     @classmethod
     def setUpTestData(cls):
         cls.request = RequestFactory().get("/")
         cls.request.session = {}

     def test_adding(self):
         self.request.session["foo"] = 1
         self.assertEqual(self.request.session, {"foo": 1})

     def test_looking(self):
         self.assertEqual(self.request.session, {})
 }}}

 Leading to:

 {{{
 test_adding (test_regression.ExampleTests.test_adding) ... ok
 test_looking (test_regression.ExampleTests.test_looking) ... FAIL

 ======================================================================
 FAIL: test_looking (test_regression.ExampleTests.test_looking)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/Users/chainz/Documents/Projects/django/tests/test_regression.py",
 line 16, in test_looking
     self.assertEqual(self.request.session, {})
 AssertionError: {'foo': 1} != {}
 - {'foo': 1}
 + {}
 }}}

 (Simplified from a real test suite.)

 Bisected to #29186 / 6220c445c40a6a7f4d442de8bde2628346153963, using these
 commands to run the above test case:

 {{{
 git bisect start facc153af7 ff8e5eacda
 git bisect run sh -c 'cd tests && ./runtests.py test_regression -v 2'
 }}}

 I see #34482 was also just opened as a regression from that same ticket.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34484#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018770c86b41-ede4f44d-4cdb-425c-8c92-78dcab8a5118-000000%40eu-central-1.amazonses.com.

Reply via email to