omnata-plugin-runtime 0.5.1a114__py3-none-any.whl → 0.5.2a117__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.
@@ -8,7 +8,7 @@ from typing import Any, List, Dict, Literal, Union, Optional
8
8
  from enum import Enum
9
9
 
10
10
  from abc import ABC
11
- from pydantic import BaseModel, Field, PrivateAttr, validator # pylint: disable=no-name-in-module
11
+ from pydantic import BaseModel, Field, PrivateAttr, SerializationInfo, model_serializer, validator # pylint: disable=no-name-in-module
12
12
 
13
13
  if tuple(sys.version_info[:2]) >= (3, 9):
14
14
  # Python 3.9 and above
@@ -110,16 +110,18 @@ class OutboundSyncAction(SubscriptableBaseModel, ABC):
110
110
  **STANDARD_OUTBOUND_SYNC_ACTIONS[data["action_name"]]().__dict__,
111
111
  }
112
112
  super().__init__(**data)
113
-
114
- def dict(self, *args, trim: bool = True, **kwargs) -> Dict[str, any]:
115
- """
116
- OutboundSyncStrategy objects can be serialized much smaller if the instance is of a Standard strategy that resides in the
117
- Omnata plugin runtime. This method trims out the unneeded attributes in these scenarios.
118
- This method also trims the actions for this strategy if it's a custom one.
119
-
120
- """
121
- excluded_fields = {} if not trim or self.custom_action else {"description"}
122
- return super().dict(exclude=excluded_fields)
113
+
114
+ @model_serializer(mode='wrap')
115
+ def ser_model(self,handler,info:SerializationInfo) -> Dict[str, Any]:
116
+ serialized:Dict[str,Any] = handler(self)
117
+ if not self.custom_action and (info.exclude_none is None or info.exclude_none == False):
118
+ return {k:v for k,v in serialized.items() if k not in [
119
+ "description"]}
120
+ return serialized
121
+
122
+ def model_dump_no_trim(self) -> Dict[str, Any]:
123
+ # we use our own special include value to signal not to trim
124
+ return self.model_dump(exclude_none=True)
123
125
 
124
126
 
125
127
  class CreateSyncAction(OutboundSyncAction):
@@ -227,7 +229,7 @@ class OutboundSyncStrategy(SubscriptableBaseModel, ABC):
227
229
  action_on_record_unchanged: Optional[OutboundSyncAction] = None
228
230
  custom_strategy: bool = True
229
231
 
230
- def __eq__(self, other):
232
+ def __eq__(self, other:OutboundSyncStrategy):
231
233
  if hasattr(other, 'custom_strategy') and hasattr(other, 'name'):
232
234
  return (
233
235
  self.custom_strategy == other.custom_strategy
@@ -251,27 +253,23 @@ class OutboundSyncStrategy(SubscriptableBaseModel, ABC):
251
253
  }
252
254
  super().__init__(**data)
253
255
 
254
- def dict(self, *args, trim: bool = True, **kwargs) -> Dict[str, any]:
255
- """
256
- OutboundSyncStrategy objects can be serialized much smaller if the instance is of a Standard strategy that resides in the
257
- Omnata plugin runtime. This method trims out the unneeded attributes in these scenarios.
258
- This method also trims the actions for this strategy if it's a custom one.
259
-
260
- """
261
- excluded_fields = (
262
- {}
263
- if not trim or self.custom_strategy
264
- else {
256
+ @model_serializer(mode='wrap')
257
+ def ser_model(self,handler,info:SerializationInfo) -> Dict[str, Any]:
258
+ serialized:Dict[str,Any] = handler(self)
259
+ if not self.custom_strategy and (info.exclude_none is None or info.exclude_none == False):
260
+ return {k:v for k,v in serialized.items() if k not in [
265
261
  "description",
266
262
  "icon_source",
267
263
  "action_on_record_create",
268
264
  "action_on_record_update",
269
265
  "action_on_record_delete",
270
- "action_on_record_unchanged",
271
- }
272
- )
273
- return super().dict(exclude=excluded_fields)
274
-
266
+ "action_on_record_unchanged"]}
267
+ return serialized
268
+
269
+ def model_dump_no_trim(self) -> Dict[str, Any]:
270
+ # we use our own special include value to signal not to trim
271
+ return self.model_dump(exclude_none=True)
272
+
275
273
 
276
274
  class CreateSyncStrategy(OutboundSyncStrategy):
277
275
  """
@@ -32,6 +32,7 @@ from .omnata_plugin import (
32
32
  OutboundSyncRequest,
33
33
  DeadlineReachedException,
34
34
  )
35
+ from pydantic import TypeAdapter
35
36
  from .rate_limiting import ApiLimits, RateLimitState
36
37
 
37
38
  # set the logger class to our custom logger so that pydantic errors are handled correctly
@@ -233,7 +234,7 @@ class PluginEntrypoint:
233
234
  stream_errors=omnata_log_handler.stream_global_errors,
234
235
  total_records_estimate=inbound_sync_request._total_records_estimate
235
236
  )
236
- return_dict["final_progress_update"] = final_progress_update.dict()
237
+ return_dict["final_progress_update"] = final_progress_update.model_dump()
237
238
  if inbound_sync_request.deadline_reached:
238
239
  # if we actually hit the deadline, this is flagged by the cancellation checking worker and the cancellation
239
240
  # token is set. We throw it here as an error since that's currently how it flows back to the engine with a DELAYED state
@@ -305,10 +306,10 @@ class PluginEntrypoint:
305
306
  )
306
307
  script_result = the_function(parameters)
307
308
  if isinstance(script_result, BaseModel):
308
- script_result = script_result.dict()
309
+ script_result = script_result.model_dump()
309
310
  elif isinstance(script_result, List):
310
311
  if len(script_result) > 0 and isinstance(script_result[0], BaseModel):
311
- script_result = [r.dict() for r in script_result]
312
+ script_result = [r.model_dump() for r in script_result]
312
313
  return script_result
313
314
 
314
315
  def inbound_list_streams(
@@ -341,10 +342,10 @@ class PluginEntrypoint:
341
342
 
342
343
  script_result = self._plugin_instance.inbound_stream_list(parameters)
343
344
  if isinstance(script_result, BaseModel):
344
- script_result = script_result.dict()
345
+ script_result = script_result.model_dump()
345
346
  elif isinstance(script_result, List):
346
347
  if len(script_result) > 0 and isinstance(script_result[0], BaseModel):
347
- script_result = [r.dict() for r in script_result]
348
+ script_result = [r.model_dump() for r in script_result]
348
349
  return script_result
349
350
 
350
351
 
@@ -365,17 +366,17 @@ class PluginEntrypoint:
365
366
  script_result = the_function(stored_value)
366
367
  if not isinstance(script_result, FormOption):
367
368
  raise ValueError(f"Expected a FormOption from function {function_name}, got {type(script_result)}")
368
- results.append(script_result.dict())
369
+ results.append(script_result.model_dump())
369
370
  return results
370
371
 
371
372
  def connection_form(self):
372
373
  logger.info("Entered connection_form method")
373
374
  form: List[ConnectionMethod] = self._plugin_instance.connection_form()
374
- return [f.dict() for f in form]
375
+ return [f.model_dump() for f in form]
375
376
 
376
377
  def create_billing_events(self, session, event_request: Dict):
377
378
  logger.info("Entered create_billing_events method")
378
- request = BillingEventRequest.model_validate(event_request)
379
+ request = TypeAdapter(BillingEventRequest).validate_python(event_request)
379
380
  events: List[SnowflakeBillingEvent] = self._plugin_instance.create_billing_events(
380
381
  request
381
382
  )
@@ -408,7 +409,7 @@ class PluginEntrypoint:
408
409
  logger.warn('Billing event creation failed due to running internally to Omnata')
409
410
  else:
410
411
  raise e
411
- return [e.dict() for e in events]
412
+ return [e.model_dump() for e in events]
412
413
 
413
414
  def get_secrets(
414
415
  self, oauth_secret_name: Optional[str], other_secrets_name: Optional[str]
@@ -461,7 +462,7 @@ class PluginEntrypoint:
461
462
  script_result = the_function(parameters)
462
463
  if isinstance(script_result, List):
463
464
  if len(script_result) > 0 and isinstance(script_result[0], BaseModel):
464
- script_result = [r.dict() for r in script_result]
465
+ script_result = [r.model_dump() for r in script_result]
465
466
  else:
466
467
  raise ValueError(f"Expected a List from function {function_name}, got {type(script_result)}")
467
468
  return script_result
@@ -531,7 +532,7 @@ class PluginEntrypoint:
531
532
  f"alter network rule {network_rule_name} set value_list = ({rule_values_string})"
532
533
  ).collect()
533
534
 
534
- return connect_response.dict()
535
+ return connect_response.model_dump()
535
536
 
536
537
  def api_limits(self,
537
538
  method:str,
@@ -564,7 +565,7 @@ class PluginEntrypoint:
564
565
  # There's a bit of parsing here that could possibly be done outside of the handler function, but this shouldn't be too expensive
565
566
  sync_parameters: Dict[str, StoredConfigurationValue] = TypeAdapter(
566
567
  Dict[str, StoredConfigurationValue]).validate_python(sync_parameters)
567
- field_mappings: StoredMappingValue = StoredMappingValue.model_validate(field_mappings)
568
+ field_mappings: StoredMappingValue = TypeAdapter(StoredMappingValue).validate_python(field_mappings)
568
569
  return self._plugin_instance.outbound_record_validator(
569
570
  sync_parameters, field_mappings, transformed_record, source_types
570
571
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.5.1a114
3
+ Version: 0.5.2a117
4
4
  Summary: Classes and common runtime components for building and running Omnata Plugins
5
5
  Author: James Weakley
6
6
  Author-email: james.weakley@omnata.com
@@ -1,12 +1,12 @@
1
1
  omnata_plugin_runtime/__init__.py,sha256=MS9d1whnfT_B3-ThqZ7l63QeC_8OEKTuaYV5wTwRpBA,1576
2
2
  omnata_plugin_runtime/api.py,sha256=FxzTqri4no8ClkOm7vZADG8aD47jcGBCTTQDEORmOJM,6326
3
- omnata_plugin_runtime/configuration.py,sha256=LvQVIKwo8XlfHf-9Jkj1GDH0U6sOKDKi3IMDyAwAnHE,35781
3
+ omnata_plugin_runtime/configuration.py,sha256=GI7RBerWjymVtXRFaAhbmgmoct-m943wta0TX0m6_z8,35790
4
4
  omnata_plugin_runtime/forms.py,sha256=hV6jVaizex20Pb9NxPx11TBPK-Yy8pREAnTtCxHo4Qo,18409
5
5
  omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
6
6
  omnata_plugin_runtime/omnata_plugin.py,sha256=zIk8dS5m4pXsVy_2im-Cd-t1uQV9hf1seosb1T2jGGs,110880
7
- omnata_plugin_runtime/plugin_entrypoints.py,sha256=xlPTI25N5G3l0bRFSkga98TIHM44NRaN2g7T5jSsqX0,29181
7
+ omnata_plugin_runtime/plugin_entrypoints.py,sha256=JirYUbPBaN0UMh9t_uAHDdhaQZ7NUhdMJ11eHRKOoNY,29302
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=DVQ_bc-mVLBkrU1PTns1MWXhHiLpSB5HkWCcdePtJ2A,25611
9
- omnata_plugin_runtime-0.5.1a114.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.5.1a114.dist-info/METADATA,sha256=yf8uYGHInQ_N6bUEZyTgvvVodiYL0mxHtj3jy94BIhU,1888
11
- omnata_plugin_runtime-0.5.1a114.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
- omnata_plugin_runtime-0.5.1a114.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.5.2a117.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.5.2a117.dist-info/METADATA,sha256=5moARb8FGRx-6ulORy_zkGj7a_kc77Jd_GsDrZIu15E,1888
11
+ omnata_plugin_runtime-0.5.2a117.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ omnata_plugin_runtime-0.5.2a117.dist-info/RECORD,,