omnata-plugin-runtime 0.2.37__tar.gz → 0.2.40__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.37
3
+ Version: 0.2.40
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.37"
3
+ version = "0.2.40"
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,26 @@ 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
+ return values
1166
+
1153
1167
  class BillingEventRequest(BaseModel):
1154
1168
  """
1155
1169
  Represents a request to provide billing events for that day.