Repository navigation
[Python] Add validate() and federated_auth() - #1118
Closed
dimitrije-djordjevic-db wants to merge 22 commits into
Closed
dimitrije-djordjevic-db wants to merge 22 commits into
dimitrije-djordjevic-db wants to merge 22 commits into
Conversation
This was referenced Nov 17, 2026
The Rust SDK lets a caller check a stream_builder() configuration with validate() before build(). Add the same method to the Python stream builder and the multiplexed stream builder, sync and async. validate() runs the Python checks, then a new native validate_stream() that resolves the settings and calls the core's StreamBuilder::validate() or MultiplexedStreamBuilder::validate(), so the core stays the only source for its own limits and defaults (such as the in-flight budget of a multiplexed stream). Like the core, it opens nothing, does not resolve authentication, and does not parse the Avro schema. It is a plain method in the async SDK too, as in Rust. It only takes a read lock on the SDK, which nothing ever write-locks, so it needs no runtime. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The multiplexed() docstring and the README still said the multiplexed builder only has ack_callback() and build(); it now has validate() too. Also group the tokio import with the other external crates. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Cover that validate() opens nothing and resolves no authentication, runs the Python checks before the native call, surfaces the core's own checks (the in-flight budget, the ordinary-only callback), decodes the descriptor but not the Avro schema, extracts the callback, and leaves the builder usable for build(). Also check the native validate_stream defaults, and that ack_callback(None) before multiplexed(n) validates and reaches the network. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Show that build() on the same builder does call the headers provider, and drop a check that repeated the validate() surface tests. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Each auth setter cleared the others by hand, and the "exactly one authentication method" check named oauth() and headers_provider() directly. Route both through hooks (_clear_auth(), _auth_methods_set(), and an _AUTH_METHODS class attribute) so a builder can add an authentication method without touching the others. Behavior and error messages are unchanged. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The persistent builder has no federated_auth(), so its message must keep naming only oauth() and headers_provider(). Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
External-IdP federation was only available through create_stream(auth=...). Add federated_auth(token) to the stream builder, taking the same FederatedToken, for ordinary and multiplexed streams and for validate(). Like the other auth setters, the last one called wins. build() and validate() make a fresh native IdpSupplier per call and pass it, with the token's databricks_client_id, as separate arguments of the native open and validate calls, as create_stream_federated does. Keeping it off StreamSettings keeps the handle a short-lived local; a cached one would freeze the first event loop in the async SDK. The returned ZerobusStream and MultiplexedStream hold the supplier's callback holder strongly and expose it to the cyclic GC, so an owner/stream/callback cycle stays collectable. Every future of the async multiplexed stream carries the holder too, since it can outlive the stream object and a recovery may need a fresh token. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The README, the multiplexed examples, and the stream_builder() changelog entry still listed only OAuth and a custom headers provider for stream builder authentication. Add federated_auth(token). Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Cover that build() and validate() pass a fresh native supplier per call with the sync or async policy and the token's cache identity, forward the Databricks client ID, replace and are replaced by the other auth setters, and keep the auth in force when multiplexed(n) was called. Also check the setter's input, the native one-auth-method rule, that a federated build reaches the network and calls the token callback once, and that failed builds and validates release the callback's owner. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Match the three-method native auth message, the federated_auth() setter message, and the native databricks_client_id check in full. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Rewrap lines that earlier doc edits left long, list the stream builder and multiplexed stream builder methods under API Changes, and mention federated_auth() next to the other auth setters in the README snippet. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Check that unacknowledged batches keep each ingest call's grouping and match the unacknowledged records, that the async stream takes and flushes another record after a cancelled flush, and that recovery_retries and recovery_backoff_ms reach the core. Pin the persistent builder's table and format messages in full. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Spell out what callers of a multiplexed stream need to handle: - An ingest call waits at most 30 seconds for a full sub-stream, then raises a retriable ZerobusException; the record was not queued. - After a sub-stream fails, every call re-raises its error, which may be retriable, so recovery means get_unacked_records() into a new stream. The README shows how, including decoding JSON records first. - Each sub-stream gets max_inflight_requests // n. - A sync stream is for one thread at a time; an async one is safe across tasks. Also list NonRetriableException and ZerobusException under the ordinary StreamBuilder.build() Raises section, as the multiplexed build() does. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The stream is marked closed only once a call observes a sub-stream failure, and wait_for_message_id() checks only the sub-stream that owns the message ID, so it can still succeed after another one failed. Say so instead of "every call raises". Also note the 30 second capacity wait on ingest_records(). Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The README recovery snippet dropped every record after the call that failed: those were never queued, and get_unacked_records() does not return them. Track how many records were queued and re-ingest the rest too. Also say "one thread per instance" for sync streams, and state the integer division of max_inflight_requests in the multiplexed() docstring, as the README does. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
A refused connection takes about 2 s on Windows, so absolute bounds failed there. Compare two opens that differ in one setting instead. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
An async open can release the callback holder after asyncio.run() returns, so a single gc.collect() raced on Windows. Retry for a bounded time; a real leak still fails. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Pin the full no-auth message in the existing auth test, check the validate() order with one missing setting, check the validate() callback type on the multiplexed builder only, and fold the "consumes nothing" check into the first validate() test. Keep one multiplexed snapshot case for federation and drop the builder cycle test that F1, F2 and F10 already cover. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
The test checks the multiplexed builder only; say why the ordinary case is not here. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
Say why each new clippy::too_many_arguments allow is needed: the native methods mirror their Python keyword signatures one argument per parameter, and the shared validate_stream helper takes all of them. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
dimitrije-djordjevic-db
force-pushed
the
effort/mux-streams-pyo3
branch
from
November 24, 2026 18:15
1be7066 to
f477802
Compare
Contributor
Author
This was referenced Nov 27, 2026
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.
Stack
What changes are proposed in this pull request?
This PR adds two methods to the stream builder from the previous PRs in this stack, for ordinary and multiplexed streams, in the sync and async SDKs.
validate()mirrors the Rust SDK'svalidate(). It runs the checksbuild()makes before connecting, without opening anything. It calls the core's ownvalidate()through the native layer, so the core stays the only source for its limits and defaults, such as the in-flight budget of a multiplexed stream. As in Rust, it does not resolve authentication or parse the Avro writer schema, sobuild()can still fail. It is available aftermultiplexed(n)too, and it is a plain method in the async SDK, as in Rust.federated_auth(token)brings external-IdP federation to the stream builder. Until now it was only available throughcreate_stream(auth=...). It takes the sameFederatedToken, and like the other auth setters, the last one called wins.build()andvalidate()create a fresh native token supplier per call, ascreate_stream(auth=...)does, so an async stream never keeps the event loop of an earlier build.create_stream()and the persistent stream builder, and also changezerobus/sdk/shared/auth.py. Whichever lands second addspersonal_access_token()tostream_builder()through the same hooks.It also completes the multiplexed stream docs from the previous PR: an ingest call waits at most 30 seconds for a full sub-stream and then raises a retriable
ZerobusExceptionwithout queuing the record; after a sub-stream fails, recovery means re-ingestingget_unacked_records()and any records not yet queued into a new stream (the README shows how); each sub-stream getsmax_inflight_requests // n; and a sync stream is for one thread per instance, while an async stream is safe across tasks.Related: #163
How is this tested?
Unless noted, the tests run in CI without a server.
tests/test_stream_builder.py,validate(): it opens nothing and resolves no authentication, runs the Python checks before the native call, surfaces the core's checks (the in-flight budget, the ordinary-only callback), decodes the descriptor but not the Avro schema, and leaves the builder usable forbuild().tests/test_stream_builder.py,federated_auth(): a fresh supplier perbuild()andvalidate()call with the token's settings, replacement by and of the other auth setters, the auth kept aftermultiplexed(n), input checks, a federated build reaching the network and calling the token callback once, and failed builds releasing the callback's owner.tests/test_stream_builder.py:recovery_retriesandrecovery_backoff_msreach the core, checked by timing a failed open.tests/test_signatures.pyandtests/test_persistent_stream.py: native argument defaults and the persistent builder's error messages, pinned in full.tests/test_multiplexed_integration.py(real server, never in CI) now also checks that unacknowledged batches keep each ingest call's grouping, and that an async stream keeps working after a cancelled flush.examples/sync_example_federated.pynow also opens a multiplexed stream withfederated_auth(). A federated stream was not run against a real server.This pull request and its description were written by Isaac.