Skip to content

Commit 7673814

Browse files
author
Lode Rosseel
committed
Drop sync extra checks
1 parent f46bac0 commit 7673814

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

docs/database.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ actively restricts where database connections may be opened:
131131
or by requesting ``transactional_db`` if you must keep sync fixtures.
132132
See :ref:`async-db-behavior` for more details.
133133

134-
- In sync tests: database access is only allowed from the main thread. Attempting to use the database connection
135-
from a different thread will raise::
136-
137-
RuntimeError: Database access is only allowed in the main thread, modify your
138-
test fixtures to be sync or use the transactional_db fixture.
139-
140-
Fix this by ensuring all database transactions run in the main thread (e.g., avoiding the use of async fixtures),
141-
or use ``transactional_db`` to allow mixing.
142-
143134

144135
.. _`multi-db`:
145136

pytest_django/plugin.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -858,25 +858,10 @@ def _unblocked_async_only(self, *args, **kwargs):
858858
elif self._real_ensure_connection is not None:
859859
self._real_ensure_connection(*args, **kwargs)
860860

861-
def _unblocked_sync_only(self, *args, **kwargs):
862-
__tracebackhide__ = True
863-
if threading.current_thread() != threading.main_thread():
864-
raise RuntimeError(
865-
"Database access is only allowed in the main thread, "
866-
"modify your test fixtures to be sync or use the transactional_db fixture."
867-
"See https://pytest-django.readthedocs.io/en/latest/database.html#db-thread-safeguards for more information."
868-
)
869-
elif self._real_ensure_connection is not None:
870-
self._real_ensure_connection(*args, **kwargs)
871-
872-
def unblock(self, sync_only=False, async_only=False) -> AbstractContextManager[None]:
861+
def unblock(self, async_only=False) -> AbstractContextManager[None]:
873862
"""Enable access to the Django database."""
874-
if sync_only and async_only:
875-
raise ValueError("Cannot use both sync_only and async_only. Choose at most one.")
876863
self._save_active_wrapper()
877-
if sync_only:
878-
self._dj_db_wrapper.ensure_connection = self._unblocked_sync_only
879-
elif async_only:
864+
if async_only:
880865
self._dj_db_wrapper.ensure_connection = self._unblocked_async_only
881866
else:
882867
self._dj_db_wrapper.ensure_connection = self._real_ensure_connection

0 commit comments

Comments
 (0)