continuo-python-runtime 0.14.0__py3-none-any.whl → 0.16.0__py3-none-any.whl

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.
@@ -0,0 +1,170 @@
1
+ """The ``drop_dependents`` validation op.
2
+
3
+ On a ``late_binding`` engine a drop of a seed's table destroys nothing else, so
4
+ after a reload the objects an operator acknowledged as reading the seed are
5
+ still there. ``drop_dependents`` drops each acknowledged object that still reads
6
+ the seed, through the adapter's ``DependentsRemoval``: deepest first, and an
7
+ object the listing no longer ties to the seed is skipped and never dropped. On a
8
+ ``cascade`` engine the load's ``DROP ... CASCADE`` already removed them, so the
9
+ op drops nothing.
10
+
11
+ The block and the exit codes follow
12
+ :mod:`~continuo_python_runtime.validation.warehouse_read`: 0 when every object
13
+ was dropped or skipped, 1 when a drop failed or nothing could be tried (an
14
+ unreachable warehouse, a failed listing), 2 when the op could not run.
15
+ """
16
+ import logging
17
+ from collections.abc import Mapping
18
+ from dataclasses import dataclass
19
+ from typing import Any, cast
20
+
21
+ from continuo_engine_contract.port import ( # type: ignore[import-untyped]
22
+ DependentsRemoval,
23
+ DroppedDependents,
24
+ discover_adapter,
25
+ )
26
+
27
+ from continuo_python_runtime.validation.warehouse_read import (
28
+ Discover,
29
+ InputError,
30
+ close_quietly,
31
+ declared_drop_semantics,
32
+ discover_and_check_env,
33
+ emit,
34
+ first_line,
35
+ json_list,
36
+ seed_node_id,
37
+ seed_relation,
38
+ )
39
+
40
+ logger = logging.getLogger("validation_drop_dependents")
41
+
42
+ # The env var naming the objects to drop.
43
+ _OBJECTS_VAR = "DROP_DEPENDENTS_OBJECTS"
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class _DropInputs:
48
+ schema: str
49
+ table: str
50
+ objects: list[str]
51
+
52
+
53
+ def _drop_inputs(env: Mapping[str, str]) -> _DropInputs:
54
+ schema, table = seed_relation(env)
55
+ objects = json_list(env, _OBJECTS_VAR, required=True)
56
+ for entry in objects:
57
+ entry_schema, dot, entry_name = entry.strip().partition(".")
58
+ if not dot or not entry_schema or not entry_name:
59
+ raise InputError(f"{_OBJECTS_VAR} entry {entry!r} is not <schema>.<name>")
60
+ return _DropInputs(schema, table, objects)
61
+
62
+
63
+ def _fields(drop_semantics: str, outcome: DroppedDependents | None) -> dict[str, Any]:
64
+ dropped = outcome.dropped if outcome else ()
65
+ failed = outcome.failed if outcome else ()
66
+ return {
67
+ "op": "drop_dependents",
68
+ "drop_semantics": drop_semantics,
69
+ "dropped": [
70
+ {"schema": d.schema, "name": d.name, "kind": d.kind, "depth": d.depth} for d in dropped
71
+ ],
72
+ "skipped": list(outcome.skipped) if outcome else [],
73
+ "failed": [
74
+ {
75
+ "schema": f.dependent.schema, "name": f.dependent.name, "kind": f.dependent.kind,
76
+ "depth": f.dependent.depth, "error": first_line(f.error),
77
+ }
78
+ for f in failed
79
+ ],
80
+ }
81
+
82
+
83
+ def _finish(
84
+ env: Mapping[str, str], code: int, message: str, drop_semantics: str = "", *,
85
+ reason: str = "", outcome: DroppedDependents | None = None,
86
+ ) -> int:
87
+ node_id = seed_node_id(env)
88
+ if code == 2:
89
+ logger.error("drop_dependents %s: %s", node_id, message)
90
+ elif code or message:
91
+ logger.warning("drop_dependents %s: %s", node_id, message)
92
+ emit("error" if code else "success", message, node_id, reason, _fields(drop_semantics, outcome))
93
+ return code
94
+
95
+
96
+ def run_drop_dependents(env: Mapping[str, str], discover: Discover = discover_adapter) -> int:
97
+ """Run ``drop_dependents`` against *env*; print its one block and return the exit code.
98
+
99
+ Reads ``PROD_SCHEMA``, ``TABLE_NAME``, ``DROP_DEPENDENTS_OBJECTS`` and the
100
+ adapter's ``required_env()`` from *env* (adapters connect from ``os.environ``,
101
+ so the runner passes that). An unexpected error still prints one ``error``
102
+ block and returns 2.
103
+ """
104
+ try:
105
+ return _drop_dependents(env, discover)
106
+ except Exception as exc:
107
+ logger.exception("drop_dependents %s failed unexpectedly", seed_node_id(env))
108
+ return _finish(env, 2, f"unexpected error: {first_line(exc)}")
109
+
110
+
111
+ def _drop_dependents(env: Mapping[str, str], discover: Discover) -> int:
112
+ try:
113
+ inputs = _drop_inputs(env)
114
+ engine, adapter_cls = discover_and_check_env(env, discover)
115
+ except InputError as exc:
116
+ return _finish(env, 2, str(exc))
117
+ seed = f"{inputs.schema}.{inputs.table}"
118
+ drop_semantics = declared_drop_semantics(adapter_cls)
119
+ if drop_semantics == "cascade":
120
+ logger.info("drop_dependents %s: engine %r drops with CASCADE; nothing to drop", seed, engine)
121
+ return _finish(
122
+ env, 0,
123
+ f"engine {engine!r} drops with CASCADE: the load's drop of {seed} already removed "
124
+ f"the objects that read it",
125
+ drop_semantics,
126
+ )
127
+ if drop_semantics != "late_binding":
128
+ return _finish(
129
+ env, 2, f"engine {engine!r} declares no known drop_semantics, got {drop_semantics!r}",
130
+ drop_semantics,
131
+ )
132
+ if not issubclass(adapter_cls, DependentsRemoval):
133
+ return _finish(
134
+ env, 2, f"engine {engine!r} cannot drop the objects that read a table", drop_semantics
135
+ )
136
+ if not inputs.objects:
137
+ return _finish(env, 0, "", drop_semantics)
138
+
139
+ try:
140
+ adapter = adapter_cls.from_env()
141
+ except Exception as exc:
142
+ return _finish(
143
+ env, 1, f"warehouse_unreachable: {first_line(exc)}", drop_semantics,
144
+ reason="warehouse_unreachable",
145
+ )
146
+ try:
147
+ outcome = cast(DependentsRemoval, adapter).drop_dependents(
148
+ inputs.schema, inputs.table, inputs.objects
149
+ )
150
+ except Exception as exc:
151
+ return _finish(
152
+ env, 1, f"listing the objects that read {seed} failed: {first_line(exc)}",
153
+ drop_semantics,
154
+ )
155
+ finally:
156
+ close_quietly(adapter)
157
+
158
+ for dependent in outcome.dropped:
159
+ logger.info("drop_dependents %s: dropped %s.%s", seed, dependent.schema, dependent.name)
160
+ notes = []
161
+ if outcome.failed:
162
+ notes.append("drop_failed: could not drop " + ", ".join(
163
+ f"{f.dependent.schema}.{f.dependent.name} ({first_line(f.error)})" for f in outcome.failed
164
+ ))
165
+ if outcome.skipped:
166
+ notes.append(f"not dropped, they do not read {seed}: " + ", ".join(outcome.skipped))
167
+ return _finish(
168
+ env, 1 if outcome.failed else 0, "; ".join(notes), drop_semantics,
169
+ reason="drop_failed" if outcome.failed else "", outcome=outcome,
170
+ )
@@ -0,0 +1,99 @@
1
+ """The ``probe_views`` validation op.
2
+
3
+ ``probe_views`` tries each view of ``PROBE_VIEWS`` with a zero-row read and
4
+ reports which ones no longer bind, and never fails the op for a view that does
5
+ not. The block and the exit codes follow
6
+ :mod:`~continuo_python_runtime.validation.warehouse_read`: a failed probe or an
7
+ unreachable warehouse is exit 0, an input or adapter problem or an unexpected
8
+ error is exit 2.
9
+ """
10
+ import logging
11
+ from collections.abc import Mapping
12
+ from typing import Any
13
+
14
+ from continuo_engine_contract.port import discover_adapter # type: ignore[import-untyped]
15
+
16
+ from continuo_python_runtime.validation.warehouse_read import (
17
+ Discover,
18
+ InputError,
19
+ close_quietly,
20
+ discover_and_check_env,
21
+ emit,
22
+ first_line,
23
+ json_list,
24
+ )
25
+
26
+ logger = logging.getLogger("validation_probe_views")
27
+
28
+
29
+ def _probe_views_input(env: Mapping[str, str]) -> list[tuple[str, str]]:
30
+ """``PROBE_VIEWS`` as ``(schema, name)`` pairs, split on the first dot, each once, in order."""
31
+ pairs: list[tuple[str, str]] = []
32
+ for entry in json_list(env, "PROBE_VIEWS", required=True):
33
+ schema, dot, name = entry.partition(".")
34
+ if not dot or not schema or not name:
35
+ raise InputError(f"PROBE_VIEWS entry {entry!r} is not <schema>.<name>")
36
+ if (schema, name) not in pairs:
37
+ pairs.append((schema, name))
38
+ return pairs
39
+
40
+
41
+ def _quote(identifier: str) -> str:
42
+ return '"' + identifier.replace('"', '""') + '"'
43
+
44
+
45
+ def _finish_probe(
46
+ env: Mapping[str, str], status: str, message: str, reason: str, checked: bool,
47
+ views: list[dict[str, Any]],
48
+ ) -> int:
49
+ node_id = env.get("NODE_ID") or "probe_views"
50
+ if status == "error":
51
+ logger.error("probe_views %s: %s", node_id, message)
52
+ elif reason:
53
+ logger.warning("probe_views %s: %s", node_id, message)
54
+ emit(status, message, node_id, reason, {"op": "probe_views", "checked": checked, "views": views})
55
+ return 2 if status == "error" else 0
56
+
57
+
58
+ def run_probe_views(env: Mapping[str, str], discover: Discover = discover_adapter) -> int:
59
+ """Run ``probe_views`` against *env*; print its one block and return the exit code.
60
+
61
+ Reads ``PROBE_VIEWS`` and the adapter's ``required_env()`` from *env*. A view
62
+ that fails its probe, or a warehouse that cannot be reached, still ends with
63
+ exit 0; only an input or adapter problem or an unexpected error is exit 2.
64
+ """
65
+ try:
66
+ return _probe_views(env, discover)
67
+ except Exception as exc:
68
+ logger.exception("probe_views failed unexpectedly")
69
+ return _finish_probe(env, "error", f"unexpected error: {first_line(exc)}", "", False, [])
70
+
71
+
72
+ def _probe_views(env: Mapping[str, str], discover: Discover) -> int:
73
+ try:
74
+ pairs = _probe_views_input(env)
75
+ _, adapter_cls = discover_and_check_env(env, discover)
76
+ except InputError as exc:
77
+ return _finish_probe(env, "error", str(exc), "", False, [])
78
+ try:
79
+ adapter = adapter_cls.from_env()
80
+ except Exception as exc:
81
+ return _finish_probe(
82
+ env, "success", f"warehouse_unreachable: {first_line(exc)}", "warehouse_unreachable", False, []
83
+ )
84
+ views: list[dict[str, Any]] = []
85
+ try:
86
+ for schema, name in pairs:
87
+ error = ""
88
+ try:
89
+ adapter.fetch(f"SELECT * FROM {_quote(schema)}.{_quote(name)} LIMIT 0")
90
+ except Exception as exc:
91
+ error = first_line(exc)
92
+ views.append({"schema": schema, "name": name, "ok": not error, "error": error})
93
+ finally:
94
+ close_quietly(adapter)
95
+ broken = [f"{v['schema']}.{v['name']}" for v in views if not v["ok"]]
96
+ for name in broken:
97
+ logger.warning("probe_views: %s does not bind", name)
98
+ message = f"{len(broken)} of {len(views)} views failed: {', '.join(broken)}" if broken else ""
99
+ return _finish_probe(env, "success", message, "", True, views)
@@ -3,7 +3,7 @@
3
3
  Dispatches on ``VALIDATION_OP`` env var (default ``build_from_sql``):
4
4
  - ``build_from_sql``: fetch the node's compiled SQL from S3 (``CANDIDATE_SQL_URI``) and
5
5
  materialize it empty (models/snapshots).
6
- - ``clone_from_prod``: clone an existing prod table's shape empty from ``PROD_SCHEMA``
6
+ - ``build_from_prod``: build the table empty, shaped like the prod table in ``PROD_SCHEMA``
7
7
  (unchanged upstreams, including seeds).
8
8
  - ``build_from_columns``: for python nodes, which have no SELECT to shape their output
9
9
  from. Fetch the node's validation spec JSON from S3 (``CANDIDATE_SPEC_URI`` —
@@ -23,12 +23,16 @@ Dispatches on ``VALIDATION_OP`` env var (default ``build_from_sql``):
23
23
  via the engine adapter and creates nothing — a test whose compiled SQL names
24
24
  a column a candidate change dropped or renamed fails the release at its
25
25
  source, before any table is built.
26
- - ``seed_preflight``: before a seed's production table is reloaded, list the objects
26
+ - ``dependents_check``: before a seed's production table is reloaded, list the objects
27
27
  (``PROD_SCHEMA``.``TABLE_NAME``) that read it and compare them with the operator's
28
28
  allowed and acknowledged lists. Needs no ``DBT_TARGET_SCHEMA`` and creates nothing.
29
29
  - ``probe_views``: try each view of ``PROBE_VIEWS`` with a zero-row read and report
30
30
  which ones no longer bind. Needs no ``DBT_TARGET_SCHEMA`` and creates nothing.
31
- The inputs and the result block of both ops are in ``preflight``.
31
+ - ``drop_dependents``: after a seed's production table is reloaded on a
32
+ ``late_binding`` engine, drop each object of ``DROP_DEPENDENTS_OBJECTS`` that still
33
+ reads it (``PROD_SCHEMA``.``TABLE_NAME``), deepest first. Needs no
34
+ ``DBT_TARGET_SCHEMA``; on a ``cascade`` engine it drops nothing.
35
+ The inputs and the result block of each op are in its own module.
32
36
 
33
37
  The engine adapter is discovered from the single installed
34
38
  ``continuo_engine.adapters`` entry point — each runner image installs exactly one.
@@ -49,7 +53,7 @@ from continuo_engine_contract.port import ( # type: ignore[import-untyped]
49
53
  )
50
54
  from continuo_python_runtime.csv_readers import reader_for
51
55
  from continuo_python_runtime.csv_source import check_header, parse_csv_uri
52
- from continuo_python_runtime.validation import preflight, s3
56
+ from continuo_python_runtime.validation import dependents_check, drop_dependents, probe_views, s3
53
57
 
54
58
  logger = logging.getLogger("validation_runner")
55
59
 
@@ -119,15 +123,20 @@ def load_candidate_spec() -> dict:
119
123
  return spec
120
124
 
121
125
 
122
- _NODE_OPS = ("build_from_sql", "clone_from_prod", "build_from_columns", "check_binds")
126
+ _NODE_OPS = ("build_from_sql", "build_from_prod", "build_from_columns", "check_binds")
123
127
  _SCHEMA_OPS = ("ensure_schema", "drop_schema")
124
- _PREFLIGHT_OPS = ("seed_preflight", "probe_views")
128
+ # The ops on a seed's dependents: each reads its own inputs and needs no candidate schema.
129
+ _DEPENDENTS_OPS = {
130
+ "dependents_check": dependents_check.run_dependents_check,
131
+ "probe_views": probe_views.run_probe_views,
132
+ "drop_dependents": drop_dependents.run_drop_dependents,
133
+ }
125
134
 
126
135
 
127
136
  def main() -> None:
128
137
  """Run one validation op end to end; exits non-zero on failure.
129
138
 
130
- Node ops (``build_from_sql``/``clone_from_prod``/``build_from_columns``)
139
+ Node ops (``build_from_sql``/``build_from_prod``/``build_from_columns``)
131
140
  materialize one empty node table and require ``TABLE_NAME``. ``check_binds``
132
141
  is also a node op and requires ``TABLE_NAME`` (for identity only, in the
133
142
  result block's ``unique_id``) but creates nothing: it bind-checks a dbt
@@ -135,19 +144,24 @@ def main() -> None:
135
144
  Schema ops (``ensure_schema``/``drop_schema``) act on the whole candidate
136
145
  schema — the executor schedules them as one-shot engine-image Jobs to own
137
146
  the candidate-schema lifecycle without connecting to the warehouse itself —
138
- and take no table. The preflight ops (``seed_preflight``/``probe_views``) read
139
- their own inputs, need no candidate schema and exit with the code ``preflight``
140
- returns.
147
+ and take no table. The ops on a seed's dependents (``dependents_check``,
148
+ ``probe_views``, ``drop_dependents``) read their own inputs, need no
149
+ candidate schema and exit with the code their own module's function
150
+ returns. An unknown op is refused before any input is read.
141
151
  """
142
152
  logging.basicConfig(
143
153
  level=logging.INFO, stream=sys.stderr, format="%(levelname)s %(name)s: %(message)s"
144
154
  )
145
155
  op = os.environ.get("VALIDATION_OP", "build_from_sql")
146
- if op in _PREFLIGHT_OPS:
147
- if op == "seed_preflight":
148
- code = preflight.run_seed_preflight(os.environ)
149
- else:
150
- code = preflight.run_probe_views(os.environ)
156
+ if op not in (*_NODE_OPS, *_SCHEMA_OPS, *_DEPENDENTS_OPS):
157
+ target_schema = os.environ.get("DBT_TARGET_SCHEMA", "")
158
+ unique_id = _node_id() or (f"schema.{target_schema}" if target_schema else "")
159
+ logger.error("unknown VALIDATION_OP %r", op)
160
+ print(result.result_block("error", f"unknown VALIDATION_OP {op!r}",
161
+ unique_id=unique_id), flush=True)
162
+ sys.exit(2)
163
+ if op in _DEPENDENTS_OPS:
164
+ code = _DEPENDENTS_OPS[op](os.environ)
151
165
  if code:
152
166
  sys.exit(code)
153
167
  return
@@ -222,14 +236,8 @@ def main() -> None:
222
236
  sys.exit(2)
223
237
  else:
224
238
  prod_schema = _require("PROD_SCHEMA")
225
- elif op in _SCHEMA_OPS:
226
- unique_id = _node_id() or f"schema.{schema}"
227
239
  else:
228
240
  unique_id = _node_id() or f"schema.{schema}"
229
- logger.error("unknown VALIDATION_OP %r", op)
230
- print(result.result_block("error", f"unknown VALIDATION_OP {op!r}",
231
- unique_id=unique_id), flush=True)
232
- sys.exit(2)
233
241
 
234
242
  # Engine selection is discovery, not configuration: the image installs one adapter.
235
243
  try:
@@ -290,8 +298,8 @@ def main() -> None:
290
298
  adapter.check_binds(read_sql)
291
299
  adapter.build_empty_from_columns(schema, table, spec["output_columns"], config)
292
300
  else:
293
- assert prod_schema is not None, "prod_schema must be set for clone_from_prod"
294
- adapter.clone_empty_from_prod(schema, prod_schema, table)
301
+ assert prod_schema is not None, "prod_schema must be set for build_from_prod"
302
+ adapter.build_empty_from_prod(schema, prod_schema, table)
295
303
  except Exception as exc:
296
304
  logger.error("ERROR op=%s on schema %s: %s", op, schema, exc)
297
305
  print(result.result_block("error", str(exc), unique_id=unique_id), flush=True)
@@ -0,0 +1,111 @@
1
+ """What the warehouse ops on a seed's dependents share: their inputs, their one block and their adapter.
2
+
3
+ The ops ``dependents_check`` (:mod:`~continuo_python_runtime.validation.dependents_check`)
4
+ and ``probe_views`` (:mod:`~continuo_python_runtime.validation.probe_views`) read the
5
+ warehouse and change nothing; ``drop_dependents``
6
+ (:mod:`~continuo_python_runtime.validation.drop_dependents`) drops the objects an
7
+ operator acknowledged. Each prints exactly one structured result block as the
8
+ last line on stdout (``continuo_engine_contract.result``) and returns the process
9
+ exit code: 0 when the op ran to its conclusion, 1 when a ``check`` stops or a
10
+ drop fails, 2 when the op could not run (a bad input, no adapter, missing adapter
11
+ env, an unexpected error). The block's ``status`` is ``error`` for exit codes 1
12
+ and 2. Diagnostics go to stderr through ``logging``; stdout carries only the block.
13
+ """
14
+ import json
15
+ import logging
16
+ from collections.abc import Callable, Mapping
17
+ from typing import Any, cast
18
+
19
+ from continuo_engine_contract import result # type: ignore[import-untyped]
20
+ from continuo_engine_contract.port import ( # type: ignore[import-untyped]
21
+ AdapterDiscoveryError,
22
+ WarehouseAdapter,
23
+ )
24
+
25
+ logger = logging.getLogger("validation_warehouse_read")
26
+
27
+ Discover = Callable[[], tuple[str, type[WarehouseAdapter]]]
28
+
29
+ # Longest driver text kept in a block; the first line only, so a block stays small.
30
+ MAX_TEXT = 500
31
+
32
+
33
+ class InputError(Exception):
34
+ """An input of the op is missing or malformed."""
35
+
36
+
37
+ def seed_node_id(env: Mapping[str, str]) -> str:
38
+ """``NODE_ID``, else ``<PROD_SCHEMA>.<TABLE_NAME>`` when both are set, else ``""``."""
39
+ schema, table = env.get("PROD_SCHEMA", ""), env.get("TABLE_NAME", "")
40
+ return env.get("NODE_ID") or (f"{schema}.{table}" if schema and table else "")
41
+
42
+
43
+ def seed_relation(env: Mapping[str, str]) -> tuple[str, str]:
44
+ """The seed's production relation, ``(PROD_SCHEMA, TABLE_NAME)``; both are required."""
45
+ for name in ("PROD_SCHEMA", "TABLE_NAME"):
46
+ if not env.get(name):
47
+ raise InputError(f"missing required env var {name}")
48
+ return env["PROD_SCHEMA"], env["TABLE_NAME"]
49
+
50
+
51
+ def declared_drop_semantics(adapter_cls: type) -> str:
52
+ """The adapter class's ``drop_semantics``, or ``""`` when it declares none (or not a string)."""
53
+ declared = getattr(adapter_cls, "drop_semantics", "")
54
+ return declared if isinstance(declared, str) else ""
55
+
56
+
57
+ def first_line(exc: BaseException) -> str:
58
+ """The first line of an exception's text, at most ``MAX_TEXT`` characters, never empty."""
59
+ text = str(exc).strip()
60
+ line = text.splitlines()[0] if text else ""
61
+ return (line or type(exc).__name__)[:MAX_TEXT]
62
+
63
+
64
+ def json_list(env: Mapping[str, str], name: str, *, required: bool) -> list[str]:
65
+ """The env var *name* as a JSON array of strings; unset or empty is ``[]`` unless *required*."""
66
+ raw = env.get(name, "")
67
+ if not raw.strip():
68
+ if required:
69
+ raise InputError(f"missing required env var {name}")
70
+ return []
71
+ try:
72
+ value = json.loads(raw)
73
+ except json.JSONDecodeError as exc:
74
+ raise InputError(f"{name} is not valid JSON: {exc}") from exc
75
+ if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
76
+ raise InputError(f"{name} must be a JSON array of strings")
77
+ return cast(list[str], value)
78
+
79
+
80
+ def emit(
81
+ status: str, message: str, unique_id: str, reason: str, fields: dict[str, Any]
82
+ ) -> None:
83
+ """Print the op's one result block, the last line on stdout."""
84
+ print(
85
+ result.result_block(
86
+ status, message, 1 if status == "error" else 0, unique_id, reason=reason, fields=fields
87
+ ),
88
+ flush=True,
89
+ )
90
+
91
+
92
+ def discover_and_check_env(
93
+ env: Mapping[str, str], discover: Discover
94
+ ) -> tuple[str, type[WarehouseAdapter]]:
95
+ """The installed adapter, after checking its required env is present in *env*."""
96
+ try:
97
+ engine, adapter_cls = discover()
98
+ except AdapterDiscoveryError as exc:
99
+ raise InputError(str(exc)) from exc
100
+ missing = [name for name in adapter_cls.required_env() if not env.get(name)]
101
+ if missing:
102
+ raise InputError(f"missing required env for engine {engine!r}: {', '.join(missing)}")
103
+ return engine, adapter_cls
104
+
105
+
106
+ def close_quietly(adapter: Any) -> None:
107
+ """Close the adapter; a failure only logs, so it never masks the op's outcome."""
108
+ try:
109
+ adapter.close()
110
+ except Exception as exc:
111
+ logger.error("adapter close failed: %s", exc)