Skip to content

Commit 96d9a1a

Browse files
author
Joel Collins
committed
Better handle missing LabThings Flask extension
1 parent 812baa1 commit 96d9a1a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

labthings/server/find.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
from . import EXTENSION_NAME
55

66

7-
def current_labthing():
7+
def current_labthing(app=None):
88
"""The LabThing instance handling current requests.
99
1010
Searches for a valid LabThing extension attached to the current Flask context.
1111
"""
1212
# We use _get_current_object so that Task threads can still
1313
# reach the Flask app object. Just using current_app returns
1414
# a wrapper, which breaks it's use in Task threads
15-
app = current_app._get_current_object() # skipcq: PYL-W0212
15+
if not app:
16+
app = current_app._get_current_object() # skipcq: PYL-W0212
1617
if not app:
1718
return None
1819
logging.debug("Active app extensions:")
1920
logging.debug(app.extensions)
2021
logging.debug("Active labthing:")
2122
logging.debug(app.extensions[EXTENSION_NAME])
22-
return app.extensions[EXTENSION_NAME]
23+
return app.extensions.get(EXTENSION_NAME, None)
2324

2425

2526
def registered_extensions(labthing_instance=None):

0 commit comments

Comments
 (0)