Raise on failed system POST instead of swallowing it - #50
Merged
Conversation
insert_self() left _resource_id unset on a non-ok response, so the failure only surfaced later as an AttributeError; _resource_id is now also initialized to None on every streamable. Fixes #42.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #42.
What was wrong
System.insert_self()assigned_resource_idonly whenres.ok, and did nothing otherwise — no raise, no log.Node.add_system(insert_resource=True)then returned normally, so the caller believed the system existed server-side. The failure surfaced much later asAttributeError: 'System' object has no attribute '_resource_id', typically fromadd_insert_datastream(), with no trace of the original HTTP error._resource_idwas only created inSystem.__init__when aresource_idkwarg was passed, so afrom_resource()-built system didn't have the attribute at all — any pre-insert access was anAttributeErrorrather than a cleanis Nonecheck.Changes
resources/system.py—insert_self()raises on a non-ok response, with label, URN, status code, and response body. The message shape matches the four siblingadd_insert_*methods that already raise.resources/base.py—StreamableResource.__init__setsself._resource_id = Noneunconditionally, fixing all three wrappers at once.System,Datastream, andControlStreamall assign their real id aftersuper().__init__(), so nothing is clobbered. This also repairsSystem.retrieve_resource(), which already guarded onif self._resource_id is Noneand therefore died before reaching that check on afrom_resource()-built system.node.py—add_systemdocstring records that a failed POST propagates and the system is not attached.docs/source/architecture/insertion.md— documents the raise.Tests
Three added, 479 passing:
test_insert_self_raises_on_failed_post— the raise carries both status code and response bodytest_resource_id_is_none_before_insert—Noneon both construction paths, andretrieve_resource()returns cleanly instead of raisingtest_add_system_does_not_attach_on_failed_insert— the issue's actual repro: raises, and leaves nothing innode.systems()Compatibility
insert_self()now raises where it previously returned. Callers that relied on the silent return were, by construction, proceeding with a system that had no server-side id — the failure mode this fixes. The raise is a plainException, matching the rest of the insert path; #47 tracks promoting all five sites to a typed hierarchy.Version bumped
0.5.2a1→0.5.3a1(behavior fix, not routine iteration).Follow-ups filed
Found in the same pass, not fixed here: #43, #44, #45, tracked with #47/#48/#49 under the umbrella #46.