Skip to content

Commit 2bba6eb

Browse files
Michael Howitzbluetech
Michael Howitz
authored andcommitted
Fix LiveServer for in-memory SQLite database
`allow_thread_sharing` is no longer writeable since Django 2.2.
1 parent 46c7d61 commit 2bba6eb

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Donald Stufft <[email protected]>
1414
Nicolas Delaby <[email protected]>
1515
Daniel Hahler <https://twitter.com/blueyed>
1616
Hasan Ramezani <[email protected]>
17+
Michael Howitz

docs/changelog.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Changelog
22
=========
33

4+
unreleased
5+
----------
6+
7+
Bugfixes
8+
^^^^^^^^
9+
10+
* Fix :fixture:`live_server` when using an in-memory SQLite database on
11+
Django >= 3.0.
12+
13+
414
v4.4.0 (2021-06-06)
515
-------------------
616

pytest_django/live_server_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, addr: str) -> None:
2424
and conn.settings_dict["NAME"] == ":memory:"
2525
):
2626
# Explicitly enable thread-shareability for this connection
27-
conn.allow_thread_sharing = True
27+
conn.inc_thread_sharing()
2828
connections_override[conn.alias] = conn
2929

3030
liveserver_kwargs["connections_override"] = connections_override
@@ -60,8 +60,12 @@ def __init__(self, addr: str) -> None:
6060

6161
def stop(self) -> None:
6262
"""Stop the server"""
63+
# Terminate the live server's thread.
6364
self.thread.terminate()
6465
self.thread.join()
66+
# Restore shared connections' non-shareability.
67+
for conn in self.thread.connections_override.values():
68+
conn.dec_thread_sharing()
6569

6670
@property
6771
def url(self) -> str:

0 commit comments

Comments
 (0)