Ticket #34865: fix_34865.patch

File fix_34865.patch, 2.1 KB (added by Fábio Domingues, 14 months ago)

Possible approach.

  • django/db/backends/base/base.py

    diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
    index 3b845ec9b3..c88162a246 100644
    a b import logging  
    55import threading
    66import time
    77import warnings
     8import weakref
    89from collections import deque
    910from contextlib import contextmanager
    1011
    class BaseDatabaseWrapper:  
    125126        # call execute(sql, params, many, context).
    126127        self.execute_wrappers = []
    127128
    128         self.client = self.client_class(self)
    129         self.creation = self.creation_class(self)
    130         self.features = self.features_class(self)
    131         self.introspection = self.introspection_class(self)
    132         self.ops = self.ops_class(self)
    133         self.validation = self.validation_class(self)
     129        weak_self = weakref.proxy(self)
     130        self.client = self.client_class(weak_self)
     131        self.creation = self.creation_class(weak_self)
     132        self.features = self.features_class(weak_self)
     133        self.introspection = self.introspection_class(weak_self)
     134        self.ops = self.ops_class(weak_self)
     135        self.validation = self.validation_class(weak_self)
    134136
    135137    def __repr__(self):
    136138        return (
    class BaseDatabaseWrapper:  
    674676        Context manager and decorator that re-throws backend-specific database
    675677        exceptions using Django's common wrappers.
    676678        """
    677         return DatabaseErrorWrapper(self)
     679        return DatabaseErrorWrapper(weakref.proxy(self))
    678680
    679681    def chunked_cursor(self):
    680682        """
  • tests/backends/sqlite/tests.py

    diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py
    index 88b514270a..eda7ff54a4 100644
    a b class Tests(TestCase):  
    7171                "NAME": "file:memorydb_test?mode=memory&cache=shared",
    7272            }
    7373        }
    74         creation = DatabaseWrapper(settings_dict).creation
     74        db = DatabaseWrapper(settings_dict)
     75        creation = db.creation
    7576        self.assertEqual(
    7677            creation._get_test_db_name(),
    7778            creation.connection.settings_dict["TEST"]["NAME"],
Back to Top