mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed ResourceWarning from unclosed SQLite connection on Python 3.13+.
- backends.sqlite.tests.ThreadSharing.test_database_sharing_in_threads
- backends.tests.ThreadTests.test_default_connection_thread_local:
on SQLite, close() doesn't explicitly close in-memory connections.
- servers.tests.LiveServerInMemoryDatabaseLockTest
- test_runner.tests.SQLiteInMemoryTestDbs.test_transaction_support
Check out https://github.com/python/cpython/pull/108015.
This commit is contained in:
@@ -6,7 +6,13 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from django.db import NotSupportedError, connection, transaction
|
||||
from django.db import (
|
||||
DEFAULT_DB_ALIAS,
|
||||
NotSupportedError,
|
||||
connection,
|
||||
connections,
|
||||
transaction,
|
||||
)
|
||||
from django.db.models import Aggregate, Avg, StdDev, Sum, Variance
|
||||
from django.db.utils import ConnectionHandler
|
||||
from django.test import TestCase, TransactionTestCase, override_settings
|
||||
@@ -222,11 +228,20 @@ class ThreadSharing(TransactionTestCase):
|
||||
available_apps = ["backends"]
|
||||
|
||||
def test_database_sharing_in_threads(self):
|
||||
thread_connections = []
|
||||
|
||||
def create_object():
|
||||
Object.objects.create()
|
||||
thread_connections.append(connections[DEFAULT_DB_ALIAS].connection)
|
||||
|
||||
create_object()
|
||||
thread = threading.Thread(target=create_object)
|
||||
thread.start()
|
||||
thread.join()
|
||||
self.assertEqual(Object.objects.count(), 2)
|
||||
main_connection = connections[DEFAULT_DB_ALIAS].connection
|
||||
try:
|
||||
create_object()
|
||||
thread = threading.Thread(target=create_object)
|
||||
thread.start()
|
||||
thread.join()
|
||||
self.assertEqual(Object.objects.count(), 2)
|
||||
finally:
|
||||
for conn in thread_connections:
|
||||
if conn is not main_connection:
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user