Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/murfey/client/contexts/tomo_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
dcg_tag = str(source).replace(f"/{environment.visit}", "")
url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
dcg_data = {
"experiment_type": "single particle",
"experiment_type_id": 37,
"experiment_type": "tomo",
"experiment_type_id": 36,
"tag": dcg_tag,
}
capture_post(url, json=dcg_data)
Expand Down Expand Up @@ -57,6 +57,9 @@

windows_path = session_data["TomographySession"]["AtlasId"]
Copy link
Contributor

@tieneupin tieneupin Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're referencing the keys "TomographySession" and "AtlasId" directly here, do we need logic to ensure KeyError exceptions are handled safely?

The other option is to do windows_path = session_data.get("TomographySession", {}).get("AtlasId", ""), which should exit safely in the if not windows_path: if-block down below.

logger.info(f"Windows path to atlas metadata found: {windows_path}")
if not windows_path:
logger.warning("No atlas metadata path found")
return

Check warning on line 62 in src/murfey/client/contexts/tomo_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo_metadata.py#L61-L62

Added lines #L61 - L62 were not covered by tests
visit_index = windows_path.split("\\").index(environment.visit)
partial_path = "/".join(windows_path.split("\\")[visit_index + 1 :])
logger.info("Partial Linux path successfully constructed from Windows path")
Expand Down Expand Up @@ -257,9 +260,12 @@
for_parsing = xml.read()
batch_xml = xmltodict.parse(for_parsing)

batch_positions_list = batch_xml["BatchPositionsList"]["BatchPositions"][
"BatchPositionParameters"
]
batch_positions_from_xml = batch_xml["BatchPositionsList"]["BatchPositions"]

Check warning on line 263 in src/murfey/client/contexts/tomo_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo_metadata.py#L263

Added line #L263 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same principle here about safely handling KeyError exceptions.

if not batch_positions_from_xml:
logger.info("No batch positions yet")
return

Check warning on line 266 in src/murfey/client/contexts/tomo_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo_metadata.py#L265-L266

Added lines #L265 - L266 were not covered by tests

batch_positions_list = batch_positions_from_xml["BatchPositionParameters"]

Check warning on line 268 in src/murfey/client/contexts/tomo_metadata.py

View check run for this annotation

Codecov / codecov/patch

src/murfey/client/contexts/tomo_metadata.py#L268

Added line #L268 was not covered by tests
if isinstance(batch_positions_list, dict):
# Case of a single batch
batch_positions_list = [batch_positions_list]
Expand Down