omnata-plugin-runtime 0.3.22a66__tar.gz → 0.3.23a68__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.3.22a66
3
+ Version: 0.3.23a68
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.3.22-a66"
3
+ version = "0.3.23-a68"
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,6 +20,7 @@ import json
20
20
  import queue
21
21
  import threading
22
22
  import time
23
+ import hashlib
23
24
  from abc import ABC, abstractmethod
24
25
  from decimal import Decimal
25
26
  from functools import partial, wraps, reduce
@@ -1181,6 +1182,9 @@ class InboundSyncRequest(SyncRequest):
1181
1182
  else:
1182
1183
  results_df["APP_IDENTIFIER"] = None
1183
1184
  if primary_key_field is not None:
1185
+ if isinstance(primary_key_field,list) and len(primary_key_field) == 1:
1186
+ # don't hash it if it's just a single value
1187
+ primary_key_field = primary_key_field[0]
1184
1188
  if isinstance(primary_key_field,list):
1185
1189
  primary_key_fields = cast(List[str],primary_key_field)
1186
1190
  primary_key_fields = sorted(primary_key_fields)
@@ -1196,8 +1200,8 @@ class InboundSyncRequest(SyncRequest):
1196
1200
  raise ValueError(
1197
1201
  f"Primary key fields '{primary_key_fields}' were not present in all records for stream {stream_name}"
1198
1202
  )
1199
- # concatenate the primary key fields to form the APP_IDENTIFIER
1200
- results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: "-".join([str(field) for field in primary_key_fields]))
1203
+ # hash all of the primary key fields
1204
+ results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: self.get_hash([str(x[field]) for field in primary_key_fields]))
1201
1205
  else:
1202
1206
  # the primary key field could contain a nested field, so we need to check for that
1203
1207
  # we need to check that each record in the results contains the primary key field
@@ -1256,6 +1260,16 @@ class InboundSyncRequest(SyncRequest):
1256
1260
  ["APP_IDENTIFIER", "STREAM_NAME", "RECORD_DATA", "RETRIEVE_DATE", "IS_DELETED"]
1257
1261
  )
1258
1262
  ]
1263
+
1264
+ def get_hash(keys:List[str]) -> str:
1265
+ """
1266
+ Creates a hash from a list of keys.
1267
+ The function will join the keys with an underscore and then create a
1268
+ SHA256 hash from the string. The function will return the hash as a string.
1269
+ """
1270
+ key_string = "_".join(keys)
1271
+ hash_object = hashlib.sha256(key_string.encode())
1272
+ return hash_object.hexdigest()
1259
1273
 
1260
1274
  def _apply_results_dataframe(self, stream_names: List[str], results_df: pandas.DataFrame):
1261
1275
  """