dbt-metricflow-sql 0.3.0__tar.gz → 0.3.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 (18) hide show
  1. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/PKG-INFO +1 -1
  2. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/pyproject.toml +1 -1
  3. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/sl_config.py +27 -2
  4. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/.gitignore +0 -0
  5. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/LICENSE +0 -0
  6. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/PYPI.md +0 -0
  7. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/README.md +0 -0
  8. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/__init__.py +0 -0
  9. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/cli.py +0 -0
  10. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/client.py +0 -0
  11. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/dependencies.py +0 -0
  12. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/docs.py +0 -0
  13. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/fragment.schema.json +0 -0
  14. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/llms-full.txt +0 -0
  15. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/plugin.py +0 -0
  16. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/semantics.py +0 -0
  17. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/src/dbt_metricflow_sql/server.py +0 -0
  18. {dbt_metricflow_sql-0.3.0 → dbt_metricflow_sql-0.3.1}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: dbt-metricflow-sql
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: dbt v1 plugin for MetricFlow
5
5
  Project-URL: Documentation, https://congenial-bassoon-7zkjv8w.pages.github.io/
6
6
  License-Expression: LicenseRef-Fivetran
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "dbt-metricflow-sql"
3
3
  # A placeholder: a release sets its tag's version, with scripts/set_version.py.
4
- version = "0.3.0"
4
+ version = "0.3.1"
5
5
  description = "dbt v1 plugin for MetricFlow"
6
6
  # Its PyPI page: README.md is for this repository.
7
7
  readme = "PYPI.md"
@@ -23,6 +23,10 @@ dbt Cloud answers its Semantic Layer routes 404 alike when the account's
23
23
  `experimental-semantic-layer` flag is off, the token lacks a permission, or the account doesn't
24
24
  exist; and, for up to an hour after the flag is switched on, from servers that don't see it yet,
25
25
  before any handler runs, so without effect. A 404 is retried for `--retry-for` seconds.
26
+
27
+ A 502, 503 or 504, from a gateway whose backend is starting or briefly gone, is retried for a
28
+ short while too, but only for a GET, PUT or DELETE: those are safe to repeat, while a POST's may
29
+ already have created what it sent. Running a `create` again is safe either way, with `--if-missing`.
26
30
  """
27
31
 
28
32
  from __future__ import annotations
@@ -80,6 +84,11 @@ _DIGITS = re.compile(r"[0-9]+")
80
84
  _DEFAULT_RETRY_SECONDS = 120.0
81
85
  _FIRST_RETRY_DELAY_SECONDS = 0.5
82
86
  _MAX_RETRY_DELAY_SECONDS = 8.0
87
+ # A gateway's answers when its backend is starting, gone, or slow: worth a few retries.
88
+ _TRANSIENT_STATUSES = frozenset({502, 503, 504})
89
+ # Methods whose request can be repeated without effect, so retrying a transient failure is safe.
90
+ _IDEMPOTENT_METHODS = frozenset({"GET", "HEAD", "PUT", "DELETE"})
91
+ _TRANSIENT_RETRY_SECONDS = 30.0
83
92
  _TIMEOUT_SECONDS = 30
84
93
  _PAGE_SIZE = 100
85
94
 
@@ -449,19 +458,35 @@ class _Api:
449
458
  not_found: ConfigError,
450
459
  retry_for: float,
451
460
  ) -> Any:
452
- """The JSON answer, retrying a 404 until `retry_for` runs out, then raising `not_found`."""
461
+ """
462
+ The JSON answer, retrying a 404 until `retry_for` runs out, then raising `not_found`, and
463
+ an idempotent request's transient failure for `_TRANSIENT_RETRY_SECONDS`.
464
+ """
453
465
  what = f"{method} {urllib.parse.urlsplit(url).path}"
454
466
  data = None if body is None else json.dumps(body).encode()
455
467
  request_headers = {**headers, "Accept": "application/json"}
456
468
  if data is not None:
457
469
  request_headers["Content-Type"] = "application/json"
458
- deadline = time.monotonic() + retry_for
470
+ start = time.monotonic()
471
+ deadline = start + retry_for
472
+ transient_deadline = start + _TRANSIENT_RETRY_SECONDS
459
473
  delay = _FIRST_RETRY_DELAY_SECONDS
460
474
  while True:
461
475
  request = urllib.request.Request(url, data=data, headers=request_headers, method=method)
462
476
  status, payload = _send(request)
463
477
  if 200 <= status < 300:
464
478
  return payload
479
+ if (
480
+ status in _TRANSIENT_STATUSES
481
+ and method in _IDEMPOTENT_METHODS
482
+ and time.monotonic() + delay <= transient_deadline
483
+ ):
484
+ print(
485
+ f"MetricFlow: {what} answered {status}; retrying in {delay:g}s", file=sys.stderr
486
+ )
487
+ time.sleep(delay)
488
+ delay = min(delay * 2, _MAX_RETRY_DELAY_SECONDS)
489
+ continue
465
490
  if status == 404 and time.monotonic() + delay > deadline:
466
491
  raise not_found
467
492
  if status != 404: