Skip to content

Commit 5495b34

Browse files
authored
Make attach_data_session_metadata_wrapper a no-op if there is no path provider (#1192)
1 parent 5954f25 commit 5495b34

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/dodal/common/beamlines/beamline_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ def set_path_provider(provider: PathProvider):
162162

163163
def get_path_provider() -> PathProvider:
164164
return PATH_PROVIDER
165+
166+
167+
def clear_path_provider() -> None:
168+
global PATH_PROVIDER
169+
del PATH_PROVIDER

src/dodal/plan_stubs/data_session.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ def attach_data_session_metadata_wrapper(
3333
Yields:
3434
Iterator[Msg]: Plan messages
3535
"""
36-
provider = provider or get_path_provider()
36+
try:
37+
provider = provider or get_path_provider()
38+
except NameError:
39+
provider = None
40+
3741
if isinstance(provider, UpdatingPathProvider):
3842
yield from bps.wait_for([provider.update])
3943
ress = yield from bps.wait_for([provider.data_session])
4044
data_session = ress[0].result()
4145
# https://github.com/DiamondLightSource/dodal/issues/452
4246
# As part of 452, write each dataCollection into their own folder, then can use resource_dir directly
4347
yield from bpp.inject_md_wrapper(plan, md={DATA_SESSION: data_session})
48+
elif provider is None:
49+
logging.warning(
50+
f"There is no PathProvider set, {attach_data_session_metadata_wrapper.__name__} will have no effect"
51+
)
52+
yield from plan
4453
else:
4554
logging.warning(
4655
f"{provider} is not an UpdatingPathProvider, {attach_data_session_metadata_wrapper.__name__} will have no effect"

tests/plan_stubs/test_data_session.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from bluesky.run_engine import RunEngine
44
from bluesky.utils import MsgGenerator
55

6+
from dodal.common.beamlines.beamline_utils import clear_path_provider
67
from dodal.plan_stubs.data_session import attach_data_session_metadata_wrapper
78

89

@@ -20,3 +21,16 @@ def fake_plan() -> MsgGenerator[None]:
2021
f"{path_provider} is not an UpdatingPathProvider, {attach_data_session_metadata_wrapper.__name__} will have no effect"
2122
in caplog.text
2223
)
24+
25+
26+
def test_attach_data_session_metadata_wrapper_with_no_provider_is_noop(
27+
caplog, RE: RunEngine
28+
):
29+
def fake_plan() -> MsgGenerator[None]:
30+
yield from []
31+
32+
clear_path_provider()
33+
plan = attach_data_session_metadata_wrapper(plan=fake_plan())
34+
RE(plan)
35+
36+
assert f"There is no PathProvider set, {attach_data_session_metadata_wrapper.__name__} will have no effect"

0 commit comments

Comments
 (0)