castor-extractor 0.3.4__py3-none-any.whl → 0.3.5__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.

Potentially problematic release.


This version of castor-extractor might be problematic. Click here for more details.

CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.5 - 2023-04-07
4
+
5
+ * Extract metadata from successful dbt runs only
6
+
3
7
  ## 0.3.4 - 2023-04-05
4
8
 
5
9
  * Enhance uploader to support `QUALITY` files
@@ -1,3 +1,4 @@
1
+ import logging
1
2
  from enum import Enum
2
3
  from typing import Optional
3
4
 
@@ -5,9 +6,12 @@ import requests
5
6
 
6
7
  from .credentials import CredentialsKey, DbtCredentials, get_value
7
8
 
9
+ logger = logging.getLogger(__name__)
10
+
8
11
  _CLOUD_URL = "https://cloud.getdbt.com/api/v2/accounts"
9
12
  _DATA_KEY = "data"
10
13
  _MANIFEST_PATH = "manifest.json"
14
+ _SUCCESSFUL_RUN_STATUS = 10
11
15
 
12
16
 
13
17
  class ContentType(Enum):
@@ -47,20 +51,32 @@ class DbtClient:
47
51
  headers=headers,
48
52
  params=params,
49
53
  )
50
- result = response.json()
51
- if content_type == ContentType.JSON:
52
- return result[_DATA_KEY]
53
- return result
54
+ try:
55
+ result = response.json()
56
+ except:
57
+ context = f"{url}, status {response.status_code}"
58
+ raise ValueError(f"Couldn't extract data from {context}")
59
+ else:
60
+ if content_type == ContentType.JSON:
61
+ return result[_DATA_KEY]
62
+ return result
54
63
 
55
64
  def _infer_account_id(self) -> int:
56
65
  result = self._call(url=_CLOUD_URL)
57
66
  return result[0]["id"]
58
67
 
59
68
  def _last_run_id(self) -> int:
69
+ """
70
+ Extract last successful run id
71
+ https://docs.getdbt.com/dbt-cloud/api-v2#tag/Runs/operation/listRunsForAccount
72
+ """
73
+
60
74
  url = f"{_CLOUD_URL}/{self._account_id}/runs/"
75
+
61
76
  params = {
62
77
  "job_definition_id": self._credentials.job_id,
63
78
  "order_by": "-finished_at",
79
+ "status": _SUCCESSFUL_RUN_STATUS,
64
80
  "limit": 1,
65
81
  }
66
82
  return self._call(url, params)[0]["id"]
@@ -72,6 +88,8 @@ class DbtClient:
72
88
  """
73
89
  run_id = self._last_run_id()
74
90
  url = f"{_CLOUD_URL}/{self._account_id}/runs/{run_id}/artifacts/{_MANIFEST_PATH}"
91
+ logger.info(f"Extracting manifest from run id {run_id} with url {url}")
92
+
75
93
  # setting text content as a workaround to this issue
76
94
  # https://stackoverflow.com/questions/68201659/dbt-cloud-api-to-extract-run-artifacts
77
95
  return self._call(url, content_type=ContentType.TEXT)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: castor-extractor
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: Extract your metadata assets.
5
5
  Home-page: https://www.castordoc.com/
6
6
  License: EULA
@@ -1,4 +1,4 @@
1
- CHANGELOG.md,sha256=ODuUyWYuKprHJfhaCgKYfd63mRmxTILFkWtYqwoznYw,4723
1
+ CHANGELOG.md,sha256=DIidPXNKp9icL0ZTvm7mnNSGno2190ncEFar6BoR0Is,4796
2
2
  LICENCE,sha256=sL-IGa4hweyya1HgzMskrRdybbIa2cktzxb5qmUgDg8,8254
3
3
  README.md,sha256=_H5aVcA57LLStpQaYm0yYndJRuw7BqQKt46D1xogRJo,3390
4
4
  castor_extractor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,7 +32,7 @@ castor_extractor/transformation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
32
32
  castor_extractor/transformation/dbt/__init__.py,sha256=fynkZOuDwD4AFcAYFdUBUbBPC5HoaQjVu-Z2BMcSnoI,91
33
33
  castor_extractor/transformation/dbt/assets.py,sha256=TqjktG7NeK_FUNAoOQJTtgCGVh8Cm9cTnoozNhXErmM,94
34
34
  castor_extractor/transformation/dbt/client/__init__.py,sha256=-9TvcGyeANOnoqceq3MnRrM2i6YzK906SZqeJqfLOpg,86
35
- castor_extractor/transformation/dbt/client/client.py,sha256=k8sxyg34JbZHV05zjJvoZhDeJEY3FAXrHQdJQBd-txU,2387
35
+ castor_extractor/transformation/dbt/client/client.py,sha256=8SdcB5edeRHUUSz7HuTq67B_6RLo9O8z5lIOjyOOrpg,2938
36
36
  castor_extractor/transformation/dbt/client/credentials.py,sha256=67mWV2AML8vt--o9-2bvBzlcigj-5ZdocUcUxdc7J30,746
37
37
  castor_extractor/uploader/__init__.py,sha256=SSRtwjg-dNoxME-RJy9G1flASiUKAC5bH1htq3CURQg,75
38
38
  castor_extractor/uploader/constant.py,sha256=hEJlWYx0dyBzgo59XUBKCYIKEODpIc2DyzwAZIiNO8g,718
@@ -259,7 +259,7 @@ castor_extractor/warehouse/synapse/queries/schema.sql,sha256=aX9xNrBD_ydwl-znGSF
259
259
  castor_extractor/warehouse/synapse/queries/table.sql,sha256=mCE8bR1Vb7j7SwZW2gafcXidQ2fo1HwxcybA8wP2Kfs,1049
260
260
  castor_extractor/warehouse/synapse/queries/user.sql,sha256=sTb_SS7Zj3AXW1SggKPLNMCd0qoTpL7XI_BJRMaEpBg,67
261
261
  castor_extractor/warehouse/synapse/queries/view_ddl.sql,sha256=3EVbp5_yTgdByHFIPLHmnoOnqqLE77SrjAwFDvu4e54,249
262
- castor_extractor-0.3.4.dist-info/entry_points.txt,sha256=kwmxu6k71-dgEuW0G5zD7LUcOsBhPCjp0cGtukkH3OA,915
263
- castor_extractor-0.3.4.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
264
- castor_extractor-0.3.4.dist-info/METADATA,sha256=Hp3hAsuqbXFxUgGA6pyKVRnjDZD0ShZ859o1VVFYb6c,6365
265
- castor_extractor-0.3.4.dist-info/RECORD,,
262
+ castor_extractor-0.3.5.dist-info/entry_points.txt,sha256=kwmxu6k71-dgEuW0G5zD7LUcOsBhPCjp0cGtukkH3OA,915
263
+ castor_extractor-0.3.5.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
264
+ castor_extractor-0.3.5.dist-info/METADATA,sha256=UjUUD5Ule0Pd-WganeadVraVcdTqtlLnWSt5TsbN8PU,6365
265
+ castor_extractor-0.3.5.dist-info/RECORD,,