Skip to content

Commit

Permalink
Better handle missing LabThings Flask extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Mar 21, 2020
1 parent 812baa1 commit 96d9a1a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions labthings/server/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
from . import EXTENSION_NAME


def current_labthing():
def current_labthing(app=None):
"""The LabThing instance handling current requests.
Searches for a valid LabThing extension attached to the current Flask context.
"""
# We use _get_current_object so that Task threads can still
# reach the Flask app object. Just using current_app returns
# a wrapper, which breaks it's use in Task threads
app = current_app._get_current_object() # skipcq: PYL-W0212
if not app:
app = current_app._get_current_object() # skipcq: PYL-W0212
if not app:
return None
logging.debug("Active app extensions:")
logging.debug(app.extensions)
logging.debug("Active labthing:")
logging.debug(app.extensions[EXTENSION_NAME])
return app.extensions[EXTENSION_NAME]
return app.extensions.get(EXTENSION_NAME, None)


def registered_extensions(labthing_instance=None):
Expand Down

0 comments on commit 96d9a1a

Please sign in to comment.