Skip to content

get_buffer() crashes on None when using list of PVs #13

Description

@kabanaty

When get_buffer() is called with a list of PVs, it uses epics.caget_many() internally. If any PV in the list is unreachable (returns None from caget_many), the method crashes with TypeError: 'NoneType' object is not subscriptable because it attempts to slice None:

buff_dict = {a_pv[:-suffix_length]: buff_dict[a_pv][0:self.n_measurements] for a_pv in buff_dict}

This affects both EventDefinition.get_buffer() (edef.py line 422) and BSABuffer.get_buffer() (sc_buffer.py line 423).

Expected behavior: When a PV in the list can't connect, get_buffer() should return None for that PV in the result dict instead of crashing. This allows callers to handle partial failures gracefully.

Reproduction:

import edef
buffer = edef.EventDefinition("test", user="user", edef_number=3)
# Pass a mix of valid and invalid PVs
buffer.get_buffer(["BPMS:LI24:801:TMIT", "FAKE:INVALID:PV:TMIT"])
# → TypeError: 'NoneType' object is not subscriptable

Proposed fix: Add a None check before slicing in the list comprehension:

buff_dict = {
    a_pv[:-suffix_length]: buff_dict[a_pv][0:self.n_measurements]
    if buff_dict[a_pv] is not None else None
    for a_pv in buff_dict
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions