atlan-application-sdk-api 3.55.0__tar.gz → 3.55.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/PKG-INFO +2 -2
  2. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_runtime/offload.py +157 -6
  3. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/sql.py +178 -8
  4. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/constants.py +21 -1
  5. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/__init__.py +3 -1
  6. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/leaves.py +32 -0
  7. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/version.py +1 -1
  8. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/pyproject.toml +4 -4
  9. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/.gitignore +0 -0
  10. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/README.md +0 -0
  11. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/api-files.txt +0 -0
  12. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/__init__.py +0 -0
  13. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_build_info.py +0 -0
  14. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_context_errors.py +0 -0
  15. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_install.py +0 -0
  16. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_logging.py +0 -0
  17. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_runtime/__init__.py +0 -0
  18. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_runtime/cgroup.py +0 -0
  19. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/_runtime/progress.py +0 -0
  20. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/__init__.py +0 -0
  21. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/_interface.py +0 -0
  22. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/_sql_failure_classifier.py +0 -0
  23. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/base.py +0 -0
  24. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/http_errors.py +0 -0
  25. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/models.py +0 -0
  26. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/sql_errors.py +0 -0
  27. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/sql_typecasters.py +0 -0
  28. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/clients/ssl_utils.py +0 -0
  29. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/__init__.py +0 -0
  30. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/_generated_tree.py +0 -0
  31. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/_listing.py +0 -0
  32. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/aws_utils.py +0 -0
  33. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/aws_utils_errors.py +0 -0
  34. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/backoff.py +0 -0
  35. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/build_identity.py +0 -0
  36. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/concurrency.py +0 -0
  37. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/errors.py +0 -0
  38. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/filter_matching.py +0 -0
  39. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/logger.py +0 -0
  40. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/models.py +0 -0
  41. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/sql_filters.py +0 -0
  42. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/sql_filters_errors.py +0 -0
  43. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/task_queue.py +0 -0
  44. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/types.py +0 -0
  45. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/common/utils.py +0 -0
  46. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/contracts/__init__.py +0 -0
  47. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/contracts/base.py +0 -0
  48. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/contracts/events.py +0 -0
  49. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/contracts/types.py +0 -0
  50. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/contracts/types_errors.py +0 -0
  51. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/__init__.py +0 -0
  52. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/errors.py +0 -0
  53. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/extra.py +0 -0
  54. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/ingress.py +0 -0
  55. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/ref.py +0 -0
  56. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/requirements.py +0 -0
  57. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/spec.py +0 -0
  58. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/types.py +0 -0
  59. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/credentials/utils.py +0 -0
  60. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/base.py +0 -0
  61. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/categories.py +0 -0
  62. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/http.py +0 -0
  63. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/errors/wire.py +0 -0
  64. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/__init__.py +0 -0
  65. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/_dispatch.py +0 -0
  66. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/_warmup.py +0 -0
  67. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/asgi.py +0 -0
  68. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/base.py +0 -0
  69. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/context.py +0 -0
  70. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/contracts.py +0 -0
  71. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/manifest.py +0 -0
  72. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/metadata_routes.py +0 -0
  73. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/object_routes.py +0 -0
  74. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/request_contract.py +0 -0
  75. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/routes.py +0 -0
  76. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/handler/service_errors.py +0 -0
  77. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/server/__init__.py +0 -0
  78. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/server/fastapi/models.py +0 -0
  79. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/__init__.py +0 -0
  80. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/contracts/__init__.py +0 -0
  81. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/contracts/base_metadata_extraction.py +0 -0
  82. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/contracts/incremental_sql.py +0 -0
  83. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/contracts/sql_metadata.py +0 -0
  84. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/application_sdk/templates/contracts/sql_query.py +0 -0
  85. {atlan_application_sdk_api-3.55.0 → atlan_application_sdk_api-3.55.1}/hatch_build.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: atlan-application-sdk-api
3
- Version: 3.55.0
3
+ Version: 3.55.1
4
4
  Summary: Experimental: the handler surface of the Atlan Application SDK, for the consolidated API host
5
5
  Project-URL: Homepage, https://github.com/atlanhq/application-sdk
6
6
  Project-URL: Source, https://github.com/atlanhq/application-sdk/tree/main/packages/api
@@ -32,7 +32,7 @@ Requires-Dist: python-dotenv<2.0.0,>=1.2.2; extra == 'aws'
32
32
  Provides-Extra: pandas
33
33
  Requires-Dist: pandas<4.0.0,>=2.2.3; extra == 'pandas'
34
34
  Provides-Extra: pyatlan
35
- Requires-Dist: authlib<2,>=1.9.1; extra == 'pyatlan'
35
+ Requires-Dist: authlib<2,>=1.9.4; extra == 'pyatlan'
36
36
  Requires-Dist: pyatlan<12,>=11.7.0; extra == 'pyatlan'
37
37
  Provides-Extra: sql
38
38
  Requires-Dist: httpx<0.29.0,>=0.27.0; extra == 'sql'
@@ -191,6 +191,35 @@ class CancelHandle:
191
191
  return
192
192
  _fire_cancel_action(action)
193
193
 
194
+ @contextlib.contextmanager
195
+ def registered(self, action: Callable[[], None]) -> Iterator[None]:
196
+ """Register *action* for the block, then put the previous action back.
197
+
198
+ For nested scopes inside one call — a helper opening its own connection
199
+ while the caller's is mid-query. A plain :meth:`set` would leave the
200
+ handle pointing at the inner connection after it closed, and the outer
201
+ query could no longer be cancelled. If a cancel lands inside the block,
202
+ the inner action fires then and the outer one fires on the way out.
203
+
204
+ Args:
205
+ action: Zero-argument callable that tells the driver to stop.
206
+
207
+ Yields:
208
+ Nothing; the scoped work runs inside the block.
209
+ """
210
+ with self._lock:
211
+ previous = self._action
212
+ self.set(action)
213
+ try:
214
+ yield
215
+ finally:
216
+ with self._lock:
217
+ fire_previous = self._requested and previous is not None
218
+ if not self._requested and self._action is action:
219
+ self._action = previous
220
+ if fire_previous:
221
+ _fire_cancel_action(previous) # type: ignore[arg-type]
222
+
194
223
  def request(self) -> None:
195
224
  """Request a cancel: fire the registered action, if any, at most once.
196
225
 
@@ -247,6 +276,107 @@ def _run_cancel_action(action: Callable[[], None]) -> None:
247
276
  )
248
277
 
249
278
 
279
+ #: The :class:`CancelHandle` of the ``run_in_thread`` call whose thread is
280
+ #: running. Set only inside the copied context the thread runs in, so the event
281
+ #: loop, other tasks and other offloaded calls never see it: a cancel is scoped
282
+ #: to the one call whose caller stopped waiting.
283
+ _CURRENT_CANCEL_HANDLE: contextvars.ContextVar[CancelHandle | None] = (
284
+ contextvars.ContextVar("_CURRENT_CANCEL_HANDLE", default=None)
285
+ )
286
+
287
+
288
+ def current_cancel_handle() -> CancelHandle | None:
289
+ """The :class:`CancelHandle` of the ``run_in_thread`` call running on this thread.
290
+
291
+ Every ``run_in_thread`` call has one — the handle bound with
292
+ :meth:`CancelHandle.bind`, or a fresh one — so code deep inside the
293
+ offloaded call can register a driver cancel without the handle being
294
+ passed down to it::
295
+
296
+ def _query() -> list[Row]:
297
+ cursor = connection.cursor()
298
+ handle = current_cancel_handle()
299
+ if handle is not None:
300
+ handle.set(cursor.cancel)
301
+ cursor.execute(sql)
302
+ return cursor.fetchall()
303
+
304
+ rows = await run_in_thread(_query)
305
+
306
+ Returns:
307
+ The handle, or ``None`` outside a ``run_in_thread`` call (on the event
308
+ loop, or in a thread the SDK did not start).
309
+ """
310
+ return _CURRENT_CANCEL_HANDLE.get()
311
+
312
+
313
+ def is_cancelled() -> bool:
314
+ """Whether the work running here has been asked to stop.
315
+
316
+ True when either:
317
+
318
+ - the ``run_in_thread`` call this thread is running was abandoned — its
319
+ awaiting task was cancelled, by Temporal or locally (``asyncio.timeout``,
320
+ a ``TaskGroup`` sibling failing). Scoped to that one call: a caller that
321
+ catches its own timeout and carries on does not see it, nor does any
322
+ other offloaded call; or
323
+ - the current Temporal activity has been asked to cancel.
324
+
325
+ A cancel does not stop an offloaded thread — Python cannot kill one — so a
326
+ long loop inside ``run_in_thread`` should check this every few seconds and
327
+ return. Safe to call anywhere: outside an activity and outside an offload it
328
+ returns ``False``.
329
+ """
330
+ handle = _CURRENT_CANCEL_HANDLE.get()
331
+ if handle is not None and handle.requested:
332
+ return True
333
+ try:
334
+ from temporalio import ( # noqa: PLC0415 — the api distribution ships this file without temporalio
335
+ activity as _activity,
336
+ )
337
+ except ImportError:
338
+ return False
339
+ return _activity.in_activity() and _activity.is_cancelled()
340
+
341
+
342
+ def raise_if_cancelled() -> None:
343
+ """Raise ``CancelledError`` if :func:`is_cancelled` is true; else return.
344
+
345
+ For the step boundary of a long loop inside ``run_in_thread``: the thread
346
+ unwinds through its ``with`` blocks and ``finally`` clauses, so files and
347
+ connections close, instead of running on after its caller has gone.
348
+
349
+ Raises ``asyncio.CancelledError``, a ``BaseException``, so the
350
+ ``except Exception`` a per-record loop uses to skip bad records does not
351
+ swallow it and keep the loop going.
352
+
353
+ Raises:
354
+ asyncio.CancelledError: The work was asked to stop.
355
+ """
356
+ if is_cancelled():
357
+ raise asyncio.CancelledError
358
+
359
+
360
+ def raise_if_offload_abandoned() -> None:
361
+ """Raise ``CancelledError`` if this ``run_in_thread`` call was abandoned.
362
+
363
+ The SDK's own check. Unlike :func:`raise_if_cancelled` it ignores the
364
+ Temporal activity's flag and reads only this call's handle, which a
365
+ Temporal cancel also reaches (it arrives as the ``CancelledError`` that
366
+ abandons the call). So an offload the SDK starts *after* a cancel and
367
+ waits on to the end — a drain, a shielded finish, cleanup in an activity
368
+ that caught its cancel — still runs to completion.
369
+
370
+ Raises:
371
+ asyncio.CancelledError: The call's caller stopped waiting. A
372
+ ``BaseException``, so no ``except Exception`` on the way out
373
+ swallows it.
374
+ """
375
+ handle = _CURRENT_CANCEL_HANDLE.get()
376
+ if handle is not None and handle.requested:
377
+ raise asyncio.CancelledError
378
+
379
+
250
380
  #: Label prefixes for the auto-holds on the two offload seams (ADR-0018 →
251
381
  #: *Feeding the tracker*, mechanism 2). The offloaded callable's own name is
252
382
  #: appended, so warn mode ranks *sites* — "run_in_thread.Cursor.execute, p99
@@ -650,8 +780,10 @@ def _abandon(slot: _OffloadSlot, future: "concurrent.futures.Future[Any]") -> No
650
780
  logger.warning(
651
781
  "Offloaded call %s for app %s outlived its caller; the thread keeps a "
652
782
  "blocking-pool slot until the call returns on its own (%d stranded for "
653
- "this app). Give the blocking call a driver-level timeout so it returns "
654
- "when its caller gives up",
783
+ "this app). Stop it when its caller gives up: check is_cancelled() "
784
+ "between steps of a long loop, register the driver's cancel on "
785
+ "current_cancel_handle() for a single long call, and give the call a "
786
+ "driver-level timeout",
655
787
  slot.label,
656
788
  slot.owner,
657
789
  count,
@@ -780,6 +912,15 @@ async def run_in_thread(
780
912
  travels on the callable, never in ``**kwargs``, so every keyword argument
781
913
  still reaches ``func`` — no name is reserved.
782
914
 
915
+ **Every call has a handle.** Without ``bind``, a fresh one is created, and
916
+ code anywhere inside the call reaches it with :func:`current_cancel_handle`
917
+ — so a driver cancel can be registered without passing the handle down.
918
+ It is requested whenever the awaiting task is cancelled, by Temporal or
919
+ locally (``asyncio.timeout``, a ``TaskGroup`` sibling failing), and that
920
+ is what :func:`is_cancelled` reports inside the thread: a long loop checks
921
+ it between steps and returns. It is scoped to this call; the caller, and
922
+ every other offloaded call, still read ``False``.
923
+
783
924
  Args:
784
925
  func: Blocking function to run. MUST have internal timeout handling.
785
926
  A :meth:`CancelHandle.bind` result is cancelled at the driver too.
@@ -794,6 +935,11 @@ async def run_in_thread(
794
935
  - ``self.context.storage`` / ``self.context.state`` — already async.
795
936
  """
796
937
  ctx = contextvars.copy_context()
938
+ # Every call gets a handle, bound or fresh, and the thread can reach it
939
+ # through `current_cancel_handle()` / `is_cancelled()`. Set in the copy, so
940
+ # only this call's thread sees it.
941
+ cancel_handle = _bound_handle(func) or CancelHandle()
942
+ ctx.run(_CURRENT_CANCEL_HANDLE.set, cancel_handle)
797
943
  loop = asyncio.get_running_loop()
798
944
  # Auto-hold, unbounded (ADR-0018 → *Feeding the tracker*, mechanism 2).
799
945
  # `run_in_thread` is a mandatory seam, so this is the one place the SDK can
@@ -816,7 +962,6 @@ async def run_in_thread(
816
962
  scopes = _OFFLOAD_SCOPES.get()
817
963
  if scopes:
818
964
  call = _tracked_offload(call, scopes, label)
819
- cancel_handle = _bound_handle(func)
820
965
  # The app's own pool on the consolidated host (``blocking_executor``), else
821
966
  # the process-wide one.
822
967
  executor = _BLOCKING_EXECUTOR_OVERRIDE.get() or _BLOCKING_EXECUTOR
@@ -836,9 +981,9 @@ async def run_in_thread(
836
981
  try:
837
982
  return await asyncio.wrap_future(future, loop=loop)
838
983
  except asyncio.CancelledError:
839
- if cancel_handle is not None:
840
- # Non-blocking: the action is handed to the cancel pool.
841
- cancel_handle.request()
984
+ # Non-blocking: any registered action goes to the cancel pool. Also
985
+ # what flips `is_cancelled()` inside the thread, whoever cancelled.
986
+ cancel_handle.request()
842
987
  _abandon(slot, future)
843
988
  raise
844
989
 
@@ -1040,6 +1185,12 @@ def submit_in_thread(
1040
1185
  never ran. Ignoring the return value is the normal case.
1041
1186
  """
1042
1187
  ctx = contextvars.copy_context()
1188
+ # Cleanup submitted from inside an offloaded call must not inherit that
1189
+ # call's handle: it runs to completion whether or not its caller survives,
1190
+ # so `raise_if_offload_abandoned()` never stops it. (The Temporal activity
1191
+ # context still travels with the copy, so inside a cancelled activity the
1192
+ # public `is_cancelled()` does report that activity's cancel.)
1193
+ ctx.run(_CURRENT_CANCEL_HANDLE.set, None)
1043
1194
  executor = _BLOCKING_EXECUTOR_OVERRIDE.get() or _BLOCKING_EXECUTOR
1044
1195
  try:
1045
1196
  future = executor.submit(ctx.run, functools.partial(func, *args, **kwargs))
@@ -234,6 +234,130 @@ def _invalidate_if_cancelled(connection: "Connection", handle: CancelHandle) ->
234
234
  connection.invalidate()
235
235
 
236
236
 
237
+ class _ChunksHoldingConnection(Iterator["pd.DataFrame"]):
238
+ """*frames*, keeping *connection* checked out until they are done.
239
+
240
+ A chunked ``read_sql_query`` reads each chunk lazily from the cursor, so the
241
+ connection must stay open until the last one. Closing it as soon as the
242
+ iterator was built (what a ``with`` around the call did) handed it back to
243
+ the pool while its cursor was still being read: a server-side cursor could
244
+ then share a connection with its next borrower, and a buffered one had
245
+ already loaded the whole result, so ``chunksize`` saved nothing.
246
+
247
+ Released on exhaustion, on a failed read, or on :meth:`close` — including a
248
+ close before the first chunk, which a generator's ``finally`` would skip.
249
+ Dropped instead of pooled when the read that closes it was cancelled.
250
+ """
251
+
252
+ def __init__(
253
+ self, connection: "Connection", frames: Iterator["pd.DataFrame"]
254
+ ) -> None:
255
+ self._connection = connection
256
+ self._frames = frames
257
+ self._closed = False
258
+
259
+ def __next__(self) -> "pd.DataFrame":
260
+ if self._closed:
261
+ raise StopIteration
262
+ try:
263
+ return next(self._frames)
264
+ except BaseException:
265
+ # StopIteration included: the last chunk is read, release now.
266
+ self.close()
267
+ raise
268
+
269
+ def close(self) -> None:
270
+ """Stop reading and release the connection; idempotent."""
271
+ if self._closed:
272
+ return
273
+ self._closed = True
274
+ try:
275
+ close_frames = getattr(self._frames, "close", None)
276
+ if close_frames is not None:
277
+ close_frames()
278
+ finally:
279
+ read = _ACTIVE_READ.get()
280
+ if read is not None:
281
+ _invalidate_if_cancelled(self._connection, read.handle)
282
+ self._connection.close()
283
+
284
+
285
+ #: What :meth:`_BatchedResults._next_frame` returns once the frames run out.
286
+ #: ``StopIteration`` cannot cross a future, so the end travels as a value.
287
+ _NO_MORE_FRAMES = object()
288
+
289
+
290
+ class _BatchedResults(Iterator["pd.DataFrame"], AsyncIterator["pd.DataFrame"]):
291
+ """``get_batched_results``' return: the same frames, iterable either way.
292
+
293
+ ``for frame in results`` behaves exactly as the plain iterator did, which
294
+ is what every existing caller relies on. ``async for frame in results``
295
+ fetches each chunk with ``run_in_thread`` instead, so the cursor read and
296
+ the DataFrame build stay off the event loop. A cancel stops any further
297
+ chunk being read and closes (and drops) the connection once the fetch in
298
+ flight returns; that fetch itself is not interrupted, since the cursor's
299
+ cancel is registered only at execute. The SDK's writers take the async
300
+ path whenever it is offered.
301
+ """
302
+
303
+ def __init__(self, frames: Iterator["pd.DataFrame"], read: _CancellableRead):
304
+ self._frames = frames
305
+ self._read = read
306
+ # Held by every fetch and by close: a close handed to the pool after a
307
+ # cancel waits for the abandoned fetch instead of closing a generator
308
+ # that is still running.
309
+ self._in_use = threading.Lock()
310
+ # Set when a failed or cancelled fetch has already handed close to a
311
+ # thread; aclose then returns at once instead of waiting on that fetch.
312
+ self._close_scheduled = False
313
+
314
+ def __iter__(self) -> "_BatchedResults":
315
+ return self
316
+
317
+ def __next__(self) -> "pd.DataFrame":
318
+ with self._in_use:
319
+ return next(self._frames)
320
+
321
+ def __aiter__(self) -> "_BatchedResults":
322
+ return self
323
+
324
+ def _next_frame(self) -> object:
325
+ with self._in_use, _reading(self._read):
326
+ return next(self._frames, _NO_MORE_FRAMES)
327
+
328
+ def close(self) -> None:
329
+ """Stop iterating and release the connection; idempotent."""
330
+ close = getattr(self._frames, "close", None)
331
+ if close is None:
332
+ return
333
+ with self._in_use, _reading(self._read):
334
+ close()
335
+
336
+ async def __anext__(self) -> "pd.DataFrame":
337
+ try:
338
+ frame = await run_in_thread(self._read.handle.bind(self._next_frame))
339
+ except BaseException:
340
+ # Cancelled or failed: release the connection once the fetch the
341
+ # thread may still be running returns.
342
+ self._close_scheduled = True
343
+ submit_in_thread(self.close)
344
+ raise
345
+ if frame is _NO_MORE_FRAMES:
346
+ raise StopAsyncIteration
347
+ return cast("pd.DataFrame", frame)
348
+
349
+ async def aclose(self) -> None:
350
+ """Async counterpart of :meth:`close`, run off the event loop.
351
+
352
+ Returns at once when a failed or cancelled fetch already scheduled the
353
+ close: waiting would hold the caller (often unwinding a cancel) until
354
+ the abandoned fetch returns.
355
+ """
356
+ if self._close_scheduled:
357
+ return
358
+ await run_in_thread(self.close)
359
+
360
+
237
361
  #: The connect-timeout keyword of each driver that has no connect timeout by
238
362
  #: default, so a black-holed host holds the connect (and its worker thread)
239
363
  #: until the OS gives up. Drivers that already bound their connect (pymysql,
@@ -912,13 +1036,40 @@ class BaseSQLClient(ClientInterface):
912
1036
  if not self.engine:
913
1037
  raise EngineNotInitializedError()
914
1038
 
915
- with self.engine.connect() as conn:
916
- try:
917
- return self._execute_pandas_query(conn, query, chunksize)
918
- finally:
919
- read = _ACTIVE_READ.get()
920
- if read is not None:
921
- _invalidate_if_cancelled(conn, read.handle)
1039
+ if chunksize is None:
1040
+ with self.engine.connect() as conn:
1041
+ try:
1042
+ return self._execute_pandas_query(conn, query, chunksize)
1043
+ finally:
1044
+ read = _ACTIVE_READ.get()
1045
+ if read is not None:
1046
+ _invalidate_if_cancelled(conn, read.handle)
1047
+
1048
+ # Chunked: the frames are read lazily from the cursor, so the
1049
+ # connection stays checked out until they are done, not until this
1050
+ # returns.
1051
+ conn = self.engine.connect()
1052
+ try:
1053
+ frames = self._execute_pandas_query(conn, query, chunksize)
1054
+ except BaseException:
1055
+ read = _ACTIVE_READ.get()
1056
+ if read is not None:
1057
+ _invalidate_if_cancelled(conn, read.handle)
1058
+ conn.close()
1059
+ raise
1060
+ read = _ACTIVE_READ.get()
1061
+ if read is not None and read.handle.requested:
1062
+ # The caller was cancelled during the execute and will never read
1063
+ # or close the result: drop the connection now rather than leave it
1064
+ # checked out until garbage collection pools it again.
1065
+ _invalidate_if_cancelled(conn, read.handle)
1066
+ conn.close()
1067
+ raise asyncio.CancelledError
1068
+ if not isinstance(frames, Iterator):
1069
+ # An override that materialised the result: nothing left to read.
1070
+ conn.close()
1071
+ return frames
1072
+ return _ChunksHoldingConnection(conn, frames)
922
1073
 
923
1074
  async def _execute_async_read_operation(
924
1075
  self, query: str, chunksize: int | None
@@ -976,6 +1127,14 @@ class BaseSQLClient(ClientInterface):
976
1127
  ) -> AsyncIterator["pd.DataFrame"] | Iterator["pd.DataFrame"]: # type: ignore
977
1128
  """Get query results as batched pandas DataFrames asynchronously.
978
1129
 
1130
+ The result is iterable both ways. ``async for frame in results`` reads
1131
+ each chunk off the event loop, and a cancel stops further reads and
1132
+ releases the connection once the chunk in flight returns; prefer it.
1133
+ ``for frame in results`` still works as it always has, but every chunk
1134
+ is then read on the iterating thread — the event loop, from async code.
1135
+ The query's connection stays checked out until the chunks are read or
1136
+ the result is closed (``close()`` / ``await aclose()``).
1137
+
979
1138
  Returns:
980
1139
  AsyncIterator["pd.DataFrame"]: Async iterator yielding batches of query results.
981
1140
 
@@ -986,7 +1145,18 @@ class BaseSQLClient(ClientInterface):
986
1145
  try:
987
1146
  # We cast to Iterator because passing chunk_size guarantees an Iterator return
988
1147
  result = await self._execute_async_read_operation(query, self.chunk_size)
989
- return cast(Iterator["pd.DataFrame"], result)
1148
+ frames = cast(Iterator["pd.DataFrame"], result)
1149
+ from sqlalchemy.ext.asyncio import ( # noqa: PLC0415 — optional dep: sqlalchemy
1150
+ AsyncEngine,
1151
+ )
1152
+
1153
+ if isinstance(self.engine, AsyncEngine) or not isinstance(frames, Iterator):
1154
+ # An async engine's frames come off a greenlet-bound session;
1155
+ # pulling them on a worker thread is not supported there.
1156
+ return frames
1157
+ return _BatchedResults(
1158
+ frames, _CancellableRead(CancelHandle(), self.cancel_cursor)
1159
+ )
990
1160
  except AppError:
991
1161
  raise
992
1162
  # conformance: ignore[E004] exception re-raised immediately as typed SqlPandasResultError; cause chain preserved via `from e`
@@ -1130,9 +1130,29 @@ INCREMENTAL_DEFAULT_STATE = "NO CHANGE"
1130
1130
  #: Base folder for DuckDB temp files (each connection gets a unique UUID subfolder)
1131
1131
  DUCKDB_COMMON_TEMP_FOLDER = "/tmp/incremental_duckdb"
1132
1132
 
1133
- #: Default memory limit for DuckDB (fixed for K8s pods)
1133
+ #: Upper bound on DuckDB's memory limit. A connection opened without an
1134
+ #: explicit ``memory_limit`` gets this when the container has no memory limit;
1135
+ #: otherwise it gets the smaller of this and a share of the container's free
1136
+ #: memory (see ``duckdb_utils.default_duckdb_memory_limit``).
1134
1137
  DUCKDB_DEFAULT_MEMORY_LIMIT = "2GB"
1135
1138
 
1139
+ #: ``DUCKDB_DEFAULT_MEMORY_LIMIT`` in bytes (DuckDB's ``GB`` is 1000^3).
1140
+ DUCKDB_MAX_MEMORY_LIMIT_BYTES = 2 * 1000**3
1141
+
1142
+ #: Share of the container's free memory (limit minus current usage) that the
1143
+ #: DuckDB connections opened without an explicit ``memory_limit`` may use
1144
+ #: between them. The rest is a reserve for the worker's own growth and for
1145
+ #: DuckDB's allocations outside its buffer manager, so a scan spills to
1146
+ #: ``temp_directory`` rather than pushing the container toward an OOM kill.
1147
+ DUCKDB_MEMORY_LIMIT_FRACTION = 0.5
1148
+
1149
+ #: Lower bound, in bytes, on a container-derived DuckDB memory limit.
1150
+ DUCKDB_MIN_MEMORY_LIMIT_BYTES = 256 * 1024 * 1024
1151
+
1152
+ #: Operator override for the default DuckDB memory limit (any DuckDB size
1153
+ #: string, e.g. ``1GB``). Empty means derive it from the container limit.
1154
+ DUCKDB_MEMORY_LIMIT_OVERRIDE = os.getenv("ATLAN_DUCKDB_MEMORY_LIMIT", "").strip()
1155
+
1136
1156
  SSL_CERT_DIR = os.getenv("SSL_CERT_DIR", "")
1137
1157
  """Custom SSL/TLS certificate directory for corporate/private CAs.
1138
1158
 
@@ -14,7 +14,7 @@ Canonical API (v3.x+)::
14
14
  RateLimitedError, UnimplementedError,
15
15
  DependencyUnavailableError, SourceUnavailableError,
16
16
  ObjectStoreReadError, ObjectStoreDownloadError,
17
- ResourceExhaustedError, DiskFullError,
17
+ ResourceExhaustedError, DiskFullError, SdrDiskFullError,
18
18
  DataIntegrityError, CancelledError, InternalError,
19
19
  classify_http_status, classify_http_exception,
20
20
  )
@@ -58,6 +58,7 @@ from application_sdk.errors.leaves import (
58
58
  PreconditionError,
59
59
  RateLimitedError,
60
60
  ResourceExhaustedError,
61
+ SdrDiskFullError,
61
62
  SourceUnavailableError,
62
63
  SourceWarmupExhaustedError,
63
64
  TaskStalledError,
@@ -161,6 +162,7 @@ __all__ = [
161
162
  "DataIntegrityError",
162
163
  "DependencyUnavailableError",
163
164
  "DiskFullError",
165
+ "SdrDiskFullError",
164
166
  "LocalVolumeUnwritableError",
165
167
  "SourceUnavailableError",
166
168
  "SourceWarmupExhaustedError",
@@ -451,6 +451,38 @@ class DiskFullError(ResourceExhaustedError):
451
451
  )
452
452
 
453
453
 
454
+ #: What the operator of a Self-Deployed Runtime agent does about a full disk.
455
+ #: Shared with the storage variant, whose constructor does not take it.
456
+ SDR_DISK_FULL_ACTION = (
457
+ "Free space on, or expand, the agent host volume backing "
458
+ "ATLAN_TEMPORARY_PATH, or reduce the volume this step stages on local disk."
459
+ )
460
+
461
+
462
+ @dataclass(kw_only=True)
463
+ class SdrDiskFullError(DiskFullError):
464
+ """A ``DiskFullError`` raised on a Self-Deployed Runtime (SDR) agent.
465
+
466
+ The full volume is on the customer's agent host, so the failure is theirs
467
+ to act on: no Atlan deployment can be resized to fix it. Ownership is a
468
+ property of the class, as for every other leaf, so readers that take
469
+ ``type(exc).audience`` (the Temporal failure log, the preflight outcome)
470
+ route it the same way as the failure envelope. The class is chosen where
471
+ the error is raised (:mod:`application_sdk.common.atomic`), from whether
472
+ the worker runs in SDR mode.
473
+
474
+ Same code (``RESOURCE_EXHAUSTED_DISK_FULL``) and retryability as its
475
+ parent, so callers that match on either keep working.
476
+ """
477
+
478
+ # Restated, not changed: the code stays the parent's so callers matching
479
+ # on ``RESOURCE_EXHAUSTED_DISK_FULL`` keep working (P003 wants each leaf to
480
+ # declare its own).
481
+ code: ClassVar[str] = "RESOURCE_EXHAUSTED_DISK_FULL"
482
+ audience: ClassVar[Audience] = Audience.USER
483
+ suggested_action: str | None = SDR_DISK_FULL_ACTION
484
+
485
+
454
486
  @dataclass(kw_only=True)
455
487
  class LocalVolumeUnwritableError(ResourceExhaustedError):
456
488
  """A local write failed because the volume is read-only or the path is unwritable.
@@ -35,5 +35,5 @@ only to reconcile ahead of a release — and deliberately, since older Dapr
35
35
  releases drop off the CDN.
36
36
  """
37
37
 
38
- __version__ = "3.55.0"
38
+ __version__ = "3.55.1"
39
39
  __dapr_version: str = "1.19.1"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "atlan-application-sdk-api"
3
- version = "3.55.0"
3
+ version = "3.55.1"
4
4
  description = "Experimental: the handler surface of the Atlan Application SDK, for the consolidated API host"
5
5
  license = "Apache-2.0"
6
6
  authors = [
@@ -25,8 +25,8 @@ dependencies = [
25
25
  # application_sdk/contracts/{base,types}.py import it; same pin as the SDK.
26
26
  "typing-extensions>=4.12.2,<5",
27
27
  "orjson>=3.11.6,<4.0.0",
28
- # Form parsing for the file-upload route. Arrives on the worker through
29
- # fastapi[standard]; the floor is the SDK's CVE constraint.
28
+ # Form parsing for the file-upload route. The SDK declares it directly with
29
+ # the same pin; the floor is the SDK's CVE constraint.
30
30
  "python-multipart>=0.0.26",
31
31
  # application_sdk.errors maps httpx failures onto the error leaves
32
32
  # (errors/http.py); same pin as the SDK's core dependency.
@@ -61,7 +61,7 @@ pyatlan = [
61
61
  # pyatlan 11.5.0 already requires authlib~=1.9.1 on Python >=3.10. Published
62
62
  # here too so a resolver that ignores requires-python cannot pick pyatlan's
63
63
  # py3.9 authlib branch for this wheel.
64
- "authlib>=1.9.1,<2", # CVE-2026-96760
64
+ "authlib>=1.9.4,<2", # CVE-2026-96760
65
65
  ]
66
66
 
67
67
  [project.urls]