Repository navigation
Conversation
…PI did Over a quota, the API can give a keyed session to a connection under another key, and the session's own connection can't tell: its session_key is still its own and it got no fallback. Stopping the session then cuts the other connection off. connect(session_key_exclusive=True) sends sessionKeyExclusive with the session key, which asks the API to keep the session to that key: it never shares it with another key, even over a quota. The flag requires a session_key; without one connect() raises ValueError before any request. Connection.session_key_exclusive reports whether the API did, read from the session's stored request like session_key. It is True only when the API says so, so it is False from an API that predates key-exclusive sessions, which ignores the flag. A caller stops a session only when both session_key is its own and session_key_exclusive is True; the README's example now does.
| session to that key even over a quota: the API never shares it with a | ||
| connection under another key, so you can stop it without cutting off | ||
| another client. Over a quota, the connection itself can still be given | ||
| another key's session, and `session_fallback` says so. |
There was a problem hiding this comment.
nit: over a quota the API can also hand this connection a plain session under its own key (test_key_exclusive_request_over_quota_is_told_it_got_its_keys_plain_session in studio-backend#3167). session_fallback is "quota" and session_key equals the caller's key, which also contradicts "It equals your key when the API kept the run on its own sessions" in the stopping section. Maybe: "Over a quota, the connection itself can still be given a shared session, even one under its own key; session_fallback says so and session_key_exclusive is False."
There was a problem hiding this comment.
Fixed in dad6d07. The session_key_exclusive bullet now uses your wording, and the stopping section no longer says a matching key means the run's own session. I also fixed session_fallback's docstring and the fallback warning, which said the session was always another key's.
…er's own key Over a quota, the API can give a session_key_exclusive request a session opened under the same key without the flag. session_fallback is then "quota" while session_key matches, so the README no longer says a matching key means the run's own session, and session_fallback and the fallback warning no longer say the session is always another key's.
Over a quota, the API can give a keyed session to a connection under another key (the quota fallback). Only that connection is told: the session's own connection still reports its own
session_keyand nosession_fallback. So the check the README recommended beforestop_session()(a matching key) can pass while another client is using the session, and the stop cuts that client off. This came up in review of wherobots/wherobots-dbt#82, which stops a dbt run's session when dbt exits.studio-backend now lets a request keep its session to its key (
sessionKeyExclusive, wherobots/studio-backend#3167, Linear WBC-1697): the API never gives that session to another key, even over a quota, and stores the flag with the session. It's on staging and goes out with the next production release. This PR lets the driver ask for it and report it, and bumps the version to 0.32.0 for release.Changes
connect(session_key_exclusive=True)sendssessionKeyExclusive: truein the request body, next tosessionKey.session_key. Without one,connect()raisesValueErrorbefore any request, as the API would refuse it.Connection.session_key_exclusivesays whether the API keeps the session to its key.connect()reads it fromapiPayload.sessionKeyExclusivein the session record it already polls until READY, as it doessession_key, so it costs no extra request.Trueonly when the API stores a JSONtrue. An API without the change ignores the request's flag and stores nothing, so it'sFalsethere, and for aconnect_direct()connection.connect_direct()passes it through toConnection.session_key_exclusive=Trueand checks bothsession_keyandsession_key_exclusivebefore stopping. The parameter list documents the new argument.Verification
ValueErrorwithout a key, with no request sent;true,false, the string"true", a missing field, no stored request;Connectionthroughconnect_direct(), and the property's default.pre-commit run --all-filespasses, anduv lock --checkpasses after the bump.microinaws-us-west-2, through wherobots-dbt with this branch installed (a 4-model run withthreads: 4):sessionKey: dbt-<invocation id>andsessionKeyExclusive: true,session_key_exclusivewasTrue, andstop_session()stopped it. Its status is nowDESTROYED.session_key_exclusivewasFalse, so the caller left the session running.Compatibility
False, so existing calls behave as before.False.