omnata-plugin-runtime 0.2.65__py3-none-any.whl → 0.2.66__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.
@@ -12,7 +12,7 @@ import queue
12
12
  import threading
13
13
  from abc import ABC, abstractmethod
14
14
  from decimal import Decimal
15
- from functools import partial, wraps
15
+ from functools import partial, wraps, reduce
16
16
  from logging import getLogger
17
17
  from typing import Any, Callable, Dict, Iterable, List, Literal, Optional, Type, cast
18
18
 
@@ -1037,28 +1037,36 @@ class InboundSyncRequest(SyncRequest):
1037
1037
  ]
1038
1038
  )
1039
1039
  primary_key_field = None
1040
- if (
1041
- self._streams_dict[stream_name].stream.source_defined_primary_key
1042
- is not None
1043
- ):
1040
+ records = results_df.to_dict("records")
1041
+ if (self._streams_dict[stream_name].stream.source_defined_primary_key is not None):
1044
1042
  primary_key_field = self._streams_dict[stream_name].stream.source_defined_primary_key
1045
1043
  elif self._streams_dict[stream_name].primary_key_field is not None:
1046
1044
  primary_key_field = self._streams_dict[stream_name].primary_key_field
1047
1045
  else:
1048
1046
  results_df["APP_IDENTIFIER"] = None
1049
1047
  if primary_key_field is not None:
1048
+ # the primary key field could contain a nested field, so we need to check for that
1050
1049
  # we need to check that each record in the results contains the primary key field
1051
1050
  if not all(
1052
1051
  primary_key_field in record["RECORD_DATA"]
1053
- for record in results_df.to_dict("records")
1052
+ for record in records
1054
1053
  ):
1055
- raise ValueError(
1056
- f"Primary key field '{primary_key_field}' was not present in all records for stream {stream_name}"
1057
- )
1054
+ if "." in primary_key_field:
1055
+ primary_key_field = primary_key_field.split(".")
1056
+
1057
+ if not all(
1058
+ get_nested_value(record["RECORD_DATA"], primary_key_field)
1059
+ for record in records
1060
+ ):
1061
+ raise ValueError(
1062
+ f"Primary key field '{primary_key_field}' was not present in all records for stream {stream_name}"
1063
+ )
1064
+ else:
1065
+ raise ValueError(
1066
+ f"Primary key field '{primary_key_field}' was not present in all records for stream {stream_name}"
1067
+ )
1058
1068
 
1059
- results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(
1060
- lambda x: x[primary_key_field]
1061
- )
1069
+ results_df["APP_IDENTIFIER"] = results_df["RECORD_DATA"].apply(lambda x: get_nested_value(x,primary_key_field))
1062
1070
  # the timestamps in Snowflake are TIMESTAMP_LTZ, so we upload in string format to ensure the
1063
1071
  # timezone information is present.
1064
1072
  results_df["RETRIEVE_DATE"] = str(datetime.datetime.now().astimezone())
@@ -1786,4 +1794,10 @@ def remove_empty_dict_values(data: Dict) -> Dict:
1786
1794
  for k, v in data.items()
1787
1795
  if v != {}
1788
1796
  }
1789
- return data
1797
+ return data
1798
+
1799
+ def get_nested_value(nested_dict:Dict, keys:List[str]):
1800
+ """
1801
+ Gets a value from a nested dictionary, using a list of keys to traverse the structure.
1802
+ """
1803
+ return reduce(lambda d, key: d.get(key) if isinstance(d, dict) else None, keys, nested_dict)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omnata-plugin-runtime
3
- Version: 0.2.65
3
+ Version: 0.2.66
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
@@ -3,10 +3,10 @@ omnata_plugin_runtime/api.py,sha256=vKq7goVPX5cPQ9CVN9l8RmpJDcqDwS5y9v1IWhWjBbk,
3
3
  omnata_plugin_runtime/configuration.py,sha256=NICse7qMtReIYY4ZCu8ng4QDJ4rFP0g3mZwc8m1Xl54,32247
4
4
  omnata_plugin_runtime/forms.py,sha256=_KqSMQG749wImLKxPZh3B3doTZMbP5jDvF6BhQNkPCM,17375
5
5
  omnata_plugin_runtime/logging.py,sha256=Q6eSqrr3SzwfVAg4r4sV1dlxeNS_PzOtZfieoWUEOZQ,3232
6
- omnata_plugin_runtime/omnata_plugin.py,sha256=DZGAH4ptL5879NJw9zBQwZ4Y3P10FY7FN4W-bUxFHwA,84359
6
+ omnata_plugin_runtime/omnata_plugin.py,sha256=VyiRQ6SwsYUUCsEcFzMQE9AfjZkEsPLgx8h9syF5eaE,85259
7
7
  omnata_plugin_runtime/plugin_entrypoints.py,sha256=dV_JOEWffdkAkofFYJMAsM_-gE9OpM2-paI2dsh5Rzo,24352
8
8
  omnata_plugin_runtime/rate_limiting.py,sha256=QO8VB1H8al6a8-ydohUmL0c5JynXG2bulmuPRs2-2-Y,14910
9
- omnata_plugin_runtime-0.2.65.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
- omnata_plugin_runtime-0.2.65.dist-info/METADATA,sha256=_o1B2vEha7riyEJKfR3cYmVu53rTnhFknqlz9v5hLmc,1086
11
- omnata_plugin_runtime-0.2.65.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
12
- omnata_plugin_runtime-0.2.65.dist-info/RECORD,,
9
+ omnata_plugin_runtime-0.2.66.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
10
+ omnata_plugin_runtime-0.2.66.dist-info/METADATA,sha256=daSdozbRb7rcP1mqGDbHj7-CKANyWnZu8QVPAfJGDiQ,1086
11
+ omnata_plugin_runtime-0.2.66.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
12
+ omnata_plugin_runtime-0.2.66.dist-info/RECORD,,