Skip to content

Commit a853a3b

Browse files
authored
Merge pull request #408
MPT-24897 Document truncation, retry and stub errors on stream()
2 parents 7789cb2 + 4beebce commit a853a3b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎docs/streaming.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ contract uses for it:
291291
Only `id` is guaranteed on a stub. No other property of the deleted row is carried. A
292292
**truthy** `deleted` marker is what identifies a stub; a record with no `$meta`, no `deleted`
293293
key, or a falsy one is data. In practice the platform omits `$meta` entirely on a normal
294-
record, so those cases are defensive rather than expected.
294+
record, so those cases are defensive rather than expected. A stub that carries no string
295+
`id` breaks the one guarantee the contract makes, so `stream()` raises `TypeError` rather
296+
than yielding a stub that identifies nothing.
295297

296298
`stream()` yields these as `DeletionStub`, never as a model, so the object cannot be mistaken
297299
for a record by code that expects one. Deserializing a stub as a model would produce an

‎mpt_api_client/http/mixins/streaming_mixin.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,20 +553,28 @@ def stream(
553553
models when ``skip_deleted`` is set.
554554
555555
Raises:
556+
MPTMaxRetryError: If opening the response fails after maximum retry attempts;
557+
transparent retry ends once the response commits, so it never follows
558+
the first record.
556559
MPTStreamingNotEnabledError: If the API does not confirm streaming mode.
557560
MPTStreamingFormatMismatchError: If the response ``Content-Type`` names a
558561
media type other than the requested format.
559562
MPTStreamingNotSupportedError: If the resource cannot stream (``501``).
560563
MPTStreamingNotAcceptableError: If the requested format is unsupported (``406``).
561564
MPTStreamingOverCapError: If the export exceeds the configured cap (``413``).
562565
MPTStreamingItemCountMissingError: If the response declares no usable item count.
566+
MPTStreamingTruncatedError: If the connection aborts mid-body, ending the
567+
response before the HTTP message completes; the records yielded before
568+
the abort are an incomplete snapshot to discard.
563569
MPTStreamingIncompleteError: If the fully consumed stream does not match the
564570
declared item count.
565571
JSONDecodeError: If the body cannot be parsed in the requested wire format —
566572
a malformed or non-object record line in the line-delimited format, or a
567573
malformed or unterminated envelope in the envelope format.
568574
ValueError: If ``stream_format`` is neither a `StreamFormat` member nor a
569575
member's value.
576+
TypeError: If a deletion stub carries no string ``id``, the one property the
577+
contract guarantees on a stub.
570578
"""
571579
# Coerce eagerly: an equal plain string becomes its member, anything else fails
572580
# with a clear ValueError instead of an AttributeError deep in header building.
@@ -736,20 +744,28 @@ async def stream(
736744
models when ``skip_deleted`` is set.
737745
738746
Raises:
747+
MPTMaxRetryError: If opening the response fails after maximum retry attempts;
748+
transparent retry ends once the response commits, so it never follows
749+
the first record.
739750
MPTStreamingNotEnabledError: If the API does not confirm streaming mode.
740751
MPTStreamingFormatMismatchError: If the response ``Content-Type`` names a
741752
media type other than the requested format.
742753
MPTStreamingNotSupportedError: If the resource cannot stream (``501``).
743754
MPTStreamingNotAcceptableError: If the requested format is unsupported (``406``).
744755
MPTStreamingOverCapError: If the export exceeds the configured cap (``413``).
745756
MPTStreamingItemCountMissingError: If the response declares no usable item count.
757+
MPTStreamingTruncatedError: If the connection aborts mid-body, ending the
758+
response before the HTTP message completes; the records yielded before
759+
the abort are an incomplete snapshot to discard.
746760
MPTStreamingIncompleteError: If the fully consumed stream does not match the
747761
declared item count.
748762
JSONDecodeError: If the body cannot be parsed in the requested wire format —
749763
a malformed or non-object record line in the line-delimited format, or a
750764
malformed or unterminated envelope in the envelope format.
751765
ValueError: If ``stream_format`` is neither a `StreamFormat` member nor a
752766
member's value.
767+
TypeError: If a deletion stub carries no string ``id``, the one property the
768+
contract guarantees on a stub.
753769
"""
754770
# Coerce eagerly: an equal plain string becomes its member, anything else fails
755771
# with a clear ValueError instead of an AttributeError deep in header building.

0 commit comments

Comments
 (0)