omnata-plugin-runtime 0.2.36__tar.gz → 0.2.39__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.2.36
3
+ Version: 0.2.39
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,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "omnata-plugin-runtime"
3
- version = "0.2.36"
3
+ version = "0.2.39"
4
4
  description = "Classes and common runtime components for building and running Omnata Plugins"
5
5
  authors = ["James Weakley <james.weakley@omnata.com>"]
6
6
  readme = "README.md"
@@ -20,7 +20,7 @@ import jinja2
20
20
  import pandas
21
21
  import pydantic
22
22
  import pydantic.json
23
- from pydantic import parse_obj_as
23
+ from pydantic import parse_obj_as, root_validator
24
24
  from dateutil.parser import parse
25
25
  from jinja2 import Environment
26
26
  from pydantic import BaseModel # pylint: disable=no-name-in-module
@@ -1144,12 +1144,25 @@ class SnowflakeBillingEvent(BaseModel):
1144
1144
 
1145
1145
  billing_class: str
1146
1146
  base_charge: Decimal
1147
- timestamp: datetime.datetime = datetime.datetime.now()
1147
+ timestamp: datetime.datetime = datetime.datetime.now(tz=datetime.timezone.utc)
1148
1148
  sub_class: Optional[str] = None
1149
1149
  start_timestamp: Optional[datetime.datetime] = None
1150
1150
  objects: List[str] = []
1151
1151
  additional_info: Dict[str, Any] = {}
1152
1152
 
1153
+ @root_validator(pre=True)
1154
+ def validate_datetime_fields(cls, values):
1155
+ # Handling timestamps, we want to be strict on supplying a timezone
1156
+ timestamp = values.get('timestamp')
1157
+ if timestamp is not None and isinstance(timestamp, datetime.datetime):
1158
+ if timestamp.tzinfo is None or timestamp.tzinfo.utcoffset(timestamp) is None:
1159
+ raise ValueError("timestamp must be timezone aware")
1160
+
1161
+ start_timestamp = values.get('start_timestamp')
1162
+ if start_timestamp is not None and isinstance(start_timestamp, datetime.datetime):
1163
+ if start_timestamp.tzinfo is None or start_timestamp.tzinfo.utcoffset(start_timestamp) is None:
1164
+ raise ValueError("start_timestamp must be timezone aware")
1165
+
1153
1166
  class BillingEventRequest(BaseModel):
1154
1167
  """
1155
1168
  Represents a request to provide billing events for that day.
@@ -1176,6 +1189,8 @@ class OmnataPlugin(ABC):
1176
1189
  # the current parameters are available here for the benefit of jinja filters,
1177
1190
  # so that they don't get in the way of the other function arguments
1178
1191
  self._configuration_parameters: Optional[SyncConfigurationParameters] = None
1192
+ # the Snowpark session shouldn't need to be used, ordinarily
1193
+ self._session: Optional[Session] = None
1179
1194
 
1180
1195
 
1181
1196
  @abstractmethod
@@ -58,6 +58,7 @@ class PluginEntrypoint:
58
58
  module = importlib.import_module(module_name)
59
59
  class_obj = getattr(module, class_name)
60
60
  self._plugin_instance: OmnataPlugin = class_obj()
61
+ self._plugin_instance._session = session # pylint: disable=protected-access
61
62
 
62
63
  def sync(self, sync_request: Dict):
63
64
  logger.info("Entered sync method")