Skip to content

OSHConnect.add_system_to_node / create_and_insert_system silently no-op on an unregistered node #43

Description

@tipatterson-dev

Problem

OSHConnect.add_system_to_node() and OSHConnect.create_and_insert_system() (oshconnectapi.py:297 and :310) both guard their whole body on if target_node in self._nodes: with no else. When the node isn't registered with the OSHConnect instance, they fall off the end and return None — no exception, no log line. Nothing is POSTed and nothing is attached, but the caller has no way to tell that from a success.

create_and_insert_system() is the worse of the two: its documented return is "the created system", so a caller doing sys = osh.create_and_insert_system(opts, node) gets None and dies later on None.add_insert_datastream(...) — the same class of delayed, misattributed failure as #42, just with a different trigger (the POST is never attempted at all rather than rejected).

Reproduce

osh = OSHConnect(name="demo")
node = Node(protocol="http", address="localhost", port=8282)  # never osh.add_node(node)

sys = osh.create_and_insert_system({"label": "S", "urn": "urn:x:1"}, node)
assert sys is None          # silently

Same for osh.add_system_to_node(system, unregistered_node) — returns None and the system is in neither osh.systems() nor node.systems().

Possible fix

Raise on the miss rather than falling through:

if target_node not in self._nodes:
    raise ValueError(
        f"Node {target_node.get_id()} is not registered with this "
        f"OSHConnect instance; call add_node() first."
    )

ValueError matches what add_datastream() already raises a few lines up for an unresolvable system id, so it's consistent with the surrounding module. Worth auditing the rest of oshconnectapi.py for the same if …: … return shape while in there.

Related: #42 (same silent-failure family, POST-rejected trigger).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions