-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
Pyright reports reportOptionalMemberAccess errors in src/smartem_agent/event_processor.py where code accesses attributes on values that could potentially be None.
Locations
Location 1: Lines 105-107
grid.acquisition_data = self.parser.parse_epu_session_manifest(str(event.file_path))
grid.acquisition_data.uuid = self.datastore.acquisition.uuid # ← Error hereProblem: parse_epu_session_manifest() returns AcquisitionData | None. If it returns None, the next line crashes accessing .uuid on None.
Is this a real bug? Yes, potentially. If parsing fails, this would raise AttributeError. It's inside a try/except so it gets caught, but the error message would be confusing ("NoneType has no attribute uuid" rather than "failed to parse manifest").
Location 2: Lines 150-151
grid = self.datastore.get_grid(grid_uuid)
grid.atlas_data = atlas_data # ← Error hereProblem: get_grid() returns self.grids.get(uuid) which is GridData | None.
Is this a real bug? Unlikely in practice - grid_uuid was validated earlier (lines 133-143 check if not grid_uuid and return ORPHANED). But there's a theoretical race condition if the grid was removed between the check and this call.
Location 3: Line 161
grid_uuid=grid.uuid, # ← Error here (same grid variable from Location 2)Same issue as Location 2 - if grid is None, accessing .uuid fails.
Recommended Fix
Add explicit None checks with early returns for clearer error handling:
grid.acquisition_data = self.parser.parse_epu_session_manifest(str(event.file_path))
if not grid.acquisition_data:
logger.error(f"Failed to parse session manifest: {event.file_path}")
return ProcessingResult.FAILED
grid.acquisition_data.uuid = self.datastore.acquisition.uuidAnd similarly for the get_grid() case:
grid = self.datastore.get_grid(grid_uuid)
if not grid:
logger.error(f"Grid {grid_uuid} not found in datastore")
return ProcessingResult.FAILEDCurrent Workaround
Type ignore comments have been added referencing this issue to unblock CI while a proper fix is implemented.