sqlmesh 0.186.1.dev4__py3-none-any.whl → 0.186.1.dev5__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.
sqlmesh/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.186.1.dev4'
21
- __version_tuple__ = version_tuple = (0, 186, 1, 'dev4')
20
+ __version__ = version = '0.186.1.dev5'
21
+ __version_tuple__ = version_tuple = (0, 186, 1, 'dev5')
@@ -13,6 +13,7 @@ from functools import partial
13
13
 
14
14
  import pydantic
15
15
  from pydantic import Field
16
+ from pydantic_core import from_json
16
17
  from packaging import version
17
18
  from sqlglot import exp
18
19
  from sqlglot.helper import subclasses
@@ -33,6 +34,7 @@ from sqlmesh.utils.pydantic import (
33
34
  field_validator,
34
35
  model_validator,
35
36
  validation_error_message,
37
+ get_concrete_types_from_typehint,
36
38
  )
37
39
  from sqlmesh.utils.aws import validate_s3_uri
38
40
 
@@ -177,6 +179,42 @@ class ConnectionConfig(abc.ABC, BaseConfig):
177
179
  return self.db
178
180
  return None
179
181
 
182
+ @model_validator(mode="before")
183
+ @classmethod
184
+ def _expand_json_strings_to_concrete_types(cls, data: t.Any) -> t.Any:
185
+ """
186
+ There are situations where a connection config class has a field that is some kind of complex type
187
+ (eg a list of strings or a dict) but the value is being supplied from a source such as an environment variable
188
+
189
+ When this happens, the value is supplied as a string rather than a Python object. We need some way
190
+ of turning this string into the corresponding Python list or dict.
191
+
192
+ Rather than doing this piecemeal on every config subclass, this provides a generic implementatation
193
+ to identify fields that may be be supplied as JSON strings and handle them transparently
194
+ """
195
+ if data and isinstance(data, dict):
196
+ for maybe_json_field_name in cls._get_list_and_dict_field_names():
197
+ if (value := data.get(maybe_json_field_name)) and isinstance(value, str):
198
+ # crude JSON check as we dont want to try and parse every string we get
199
+ value = value.strip()
200
+ if value.startswith("{") or value.startswith("["):
201
+ data[maybe_json_field_name] = from_json(value)
202
+
203
+ return data
204
+
205
+ @classmethod
206
+ def _get_list_and_dict_field_names(cls) -> t.Set[str]:
207
+ field_names = set()
208
+ for name, field in cls.model_fields.items():
209
+ if field.annotation:
210
+ field_types = get_concrete_types_from_typehint(field.annotation)
211
+
212
+ # check if the field type is something that could concievably be supplied as a json string
213
+ if any(ft is t for t in (list, tuple, set, dict) for ft in field_types):
214
+ field_names.add(name)
215
+
216
+ return field_names
217
+
180
218
 
181
219
  class DuckDBAttachOptions(BaseConfig):
182
220
  type: str
sqlmesh/utils/pydantic.py CHANGED
@@ -306,6 +306,24 @@ def cron_validator(v: t.Any) -> str:
306
306
  return v
307
307
 
308
308
 
309
+ def get_concrete_types_from_typehint(typehint: type[t.Any]) -> set[type[t.Any]]:
310
+ concrete_types = set()
311
+ unpacked = t.get_origin(typehint)
312
+ if unpacked is None:
313
+ if type(typehint) == type(type):
314
+ return {typehint}
315
+ elif unpacked is t.Union:
316
+ for item in t.get_args(typehint):
317
+ if str(item).startswith("typing."):
318
+ concrete_types |= get_concrete_types_from_typehint(item)
319
+ else:
320
+ concrete_types.add(item)
321
+ else:
322
+ concrete_types.add(unpacked)
323
+
324
+ return concrete_types
325
+
326
+
309
327
  if t.TYPE_CHECKING:
310
328
  SQLGlotListOfStrings = t.List[str]
311
329
  SQLGlotString = str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlmesh
3
- Version: 0.186.1.dev4
3
+ Version: 0.186.1.dev5
4
4
  Summary: Next-generation data transformation framework
5
5
  Author-email: "TobikoData Inc." <engineering@tobikodata.com>
6
6
  License: Apache License
@@ -1,5 +1,5 @@
1
1
  sqlmesh/__init__.py,sha256=69xw6bTmi4cW90M-sl3g6wLDgxVcLHcKg1q8GS3lqyA,7466
2
- sqlmesh/_version.py,sha256=nZNgbGbDzUCLzSZHhV7u6sUFSQ-y2tAU1zZN-q70hlk,528
2
+ sqlmesh/_version.py,sha256=3v3CElNhp7edOXQqADP-xzMSjCYE9ldTFk_BbXg7f8U,528
3
3
  sqlmesh/magics.py,sha256=JHorAZNtezf123jmTyNSoUC9yHmv-08hMP205PJmmIo,39750
4
4
  sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -41,7 +41,7 @@ sqlmesh/core/config/__init__.py,sha256=b4gFb04tpeZpowqJD-7h3U3TLgxrpQhZahVEAo6VW
41
41
  sqlmesh/core/config/base.py,sha256=t8NQmsgQoZSc-k0dlDiCb8t1jj0AMYdGZ-6se9q_Pks,4898
42
42
  sqlmesh/core/config/categorizer.py,sha256=6vzUoNLjR6GOEb_2mYVz2TwmMv2BfldgHX2u-Le5HZs,1975
43
43
  sqlmesh/core/config/common.py,sha256=-o_HoRFtR4u84frg_TLno7z7vS9II6ASiOayb59MKHo,2806
44
- sqlmesh/core/config/connection.py,sha256=scyhg-gq0czu7-2y9n1tBKnLfM0jT51QaYR_hFCeQU8,73917
44
+ sqlmesh/core/config/connection.py,sha256=NlTFCqRVA9S18EfdXELH3Qb79Qfj84Tt-_eW0-4P0Eg,75808
45
45
  sqlmesh/core/config/feature_flag.py,sha256=JRcD31OG_t2cYc24meKbHDGB0iVID0P07V2oOeB_mgA,203
46
46
  sqlmesh/core/config/format.py,sha256=6CXFbvnor56xbldKE-Vrm9k_ABRoY4v6vgIb3mCihiQ,1355
47
47
  sqlmesh/core/config/gateway.py,sha256=tYngyqwd_4Qr9lhcv2hlvLvb_2pgYYtKu6hdGsTr-4I,1931
@@ -264,11 +264,11 @@ sqlmesh/utils/jinja.py,sha256=6Iob2Pv88L2rCaHyl_V90b5GKsG9hI10Ua_FRWhQIl0,23628
264
264
  sqlmesh/utils/metaprogramming.py,sha256=i1rxWi-oxdh1VwKoBh5Qvy0GgHm9GaDZMvIrv3QXGt4,23083
265
265
  sqlmesh/utils/migration.py,sha256=R7Ck6FX-LfcujGy7sgS0kDWlK-xAEBODr3gqIQ8gC08,835
266
266
  sqlmesh/utils/pandas.py,sha256=uKI-ygEtMcGDRzXdBu0RkGmMBkYxwu5O2Wabho841Ls,2196
267
- sqlmesh/utils/pydantic.py,sha256=dywc9i-diWLA3vB-X_28I8NX3BPoSWAjcaP31zkzr0k,11115
267
+ sqlmesh/utils/pydantic.py,sha256=I898jAFqa3qU6lG2uPpRebVFncOUo8ZrLWM_R3K3DHU,11685
268
268
  sqlmesh/utils/rich.py,sha256=xNZyPCqEc4TAlJlsEthg-5eYUWpaizz0QjBzO7a1Yv4,1509
269
269
  sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
270
270
  sqlmesh/utils/yaml.py,sha256=np-WVcwmwsKghCgAj1OBBMsK1SXSRn4wR-H37cGiFr8,2282
271
- sqlmesh-0.186.1.dev4.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
271
+ sqlmesh-0.186.1.dev5.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
272
272
  web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
273
273
  web/client/dist/index.html,sha256=xQIU9G6dbuTnmbHZ61bSYbh0gYz9A2lb4BRwLlXL94Y,5472
274
274
  web/client/dist/assets/Audits-Dcl7Y5yf.js,sha256=D2CfXzrdXFdD_-7c51tBJCKNwUY9yGeIpDEaRae7V8I,1041
@@ -386,8 +386,8 @@ web/server/api/endpoints/models.py,sha256=ud-lRwriyI_OYg9tZchrBgeiXELiRTLNEodraf
386
386
  web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
387
387
  web/server/api/endpoints/plan.py,sha256=OYuQ_4dgbhG9ibTcX1a8mvYgH3ANxw9Fhbb4wg6QWqc,9222
388
388
  web/server/api/endpoints/table_diff.py,sha256=Wd5YxeKbZB7AkrDvqFgvV9ZQlnKYOF1n5W_w2EHE_Zw,2085
389
- sqlmesh-0.186.1.dev4.dist-info/METADATA,sha256=QZQyCEcO0vO_kXhiN3InAityt4DOunO6_rSocKbkfHk,25523
390
- sqlmesh-0.186.1.dev4.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
391
- sqlmesh-0.186.1.dev4.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
392
- sqlmesh-0.186.1.dev4.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
393
- sqlmesh-0.186.1.dev4.dist-info/RECORD,,
389
+ sqlmesh-0.186.1.dev5.dist-info/METADATA,sha256=NiKDb3CP2KKR8HBi_lw8Gpwnx38auqfQg0rNmy3yifg,25523
390
+ sqlmesh-0.186.1.dev5.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
391
+ sqlmesh-0.186.1.dev5.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
392
+ sqlmesh-0.186.1.dev5.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
393
+ sqlmesh-0.186.1.dev5.dist-info/RECORD,,