Skip to content

System.insert_self() silently swallows failed POSTs, causing downstream AttributeError #42

Closed

Description

@tipatterson-dev

Found live while running OSHConnectBroker-Py against a fleet node whose disk was full (every POST returned HTTP 500) — vendored wheel from the nats-mode-fix branch.

System.insert_self() (resources/system.py) only assigns self._resource_id when res.ok; on a non-ok response it neither raises nor records the failure. Callers like Node.add_system(insert_resource=True) then return normally, so the caller believes the system was inserted. The failure finally surfaces far away as:

AttributeError: 'System' object has no attribute '_resource_id'

e.g. in System.add_insert_datastream() (parent_res_id=self._resource_id) — with no hint of the original HTTP error. Note _resource_id is only created in __init__ when a resource_id kwarg is passed, so a from_resource()-built System doesn't even have the attribute set to None — any pre-insert access is an AttributeError rather than a clean is None check.

Suggested fix (either or both):

  1. insert_self() raises (or at minimum logs at error level and sets a failed flag) when res.ok is false, including status code and response text.
  2. Initialize self._resource_id = None unconditionally in __init__ so downstream code can do a clean None check instead of dying on AttributeError.

Repro: point add_system(insert_resource=True) at any node that rejects the POST (500/4xx) and then call add_insert_datastream() on the returned System.

Downstream context: Botts-Innovative-Research/OSHConnectBroker-Py#8 (E2E findings comment).

Activity

  1. tipatterson-dev commented on Jul 28, 2026

    @tipatterson-dev
    CollaboratorAuthor

    Two more manifestations of this bug family found during downstream E2E (OSHConnectBroker-Py#13): (a) System.from_resource() / discovery never populates _resource_id even though the parsed SystemResource carries system_id — every get_id() on a discovered system raises AttributeError; (b) control streams discovered via System.discover_controlstreams() lack their parent system id, so NATS subject construction fails with 'parent system id is unresolved' until the caller manually invokes set_parent_resource_id(). Downstream worked around both (_safe_id fallback + explicit parent set on adoption), but wrapper hydration on discovery would fix the whole class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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