#35548: An error in TestCase.setUpTestData() leaks data on databases without
transactions
-----------------------------------+------------------------------------
     Reporter:  Tim Graham         |                    Owner:  nobody
         Type:  Bug                |                   Status:  new
    Component:  Testing framework  |                  Version:  dev
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------
Changes (by Simon Charette):

 * stage:  Unreviewed => Accepted

Comment:

 I think the following should do and also avoid a lack of rolling back
 transaction when they are supported

 {{{#!diff
 diff --git a/django/test/testcases.py b/django/test/testcases.py
 index f1c6b5ae9c..5cd90a7415 100644
 --- a/django/test/testcases.py
 +++ b/django/test/testcases.py
 @@ -7,7 +7,7 @@
  import threading
  import unittest
  from collections import Counter
 -from contextlib import contextmanager
 +from contextlib import contextmanager, suppress
  from copy import copy, deepcopy
  from difflib import get_close_matches
  from functools import wraps
 @@ -1125,6 +1125,11 @@ def _pre_setup(self):
          try:
              self._fixture_setup()
          except Exception:
 +            # Attempt to teardown fixtures on exception during setup as
 +            # `_post_teardown` won't be triggered to cleanup state when
 an
 +            # an exception is surfaced to `SimpleTestCase._pre_setup`.
 +            with suppress(Exception):
 +                self._fixture_teardown()
              if self.available_apps is not None:
                  apps.unset_available_apps()
                  setting_changed.send(
 }}}

 Only lightly tested though.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35548#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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701903ba256b1-fb473e79-fd08-476e-9096-98605269db69-000000%40eu-central-1.amazonses.com.

Reply via email to