From 16aaf9cad5de007fcc7ac9d255c58081f2f55a33 Mon Sep 17 00:00:00 2001 From: Rich Piazza Date: Fri, 13 Sep 2024 15:14:17 -0400 Subject: [PATCH] add id binding for dictionaries --- stix2/datastore/relational_db/input_creation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stix2/datastore/relational_db/input_creation.py b/stix2/datastore/relational_db/input_creation.py index 006b4fed..e469a7f2 100644 --- a/stix2/datastore/relational_db/input_creation.py +++ b/stix2/datastore/relational_db/input_creation.py @@ -38,10 +38,7 @@ def generate_insert_information(self, dictionary_name, stix_object, **kwargs): schema_name = kwargs.get("schema_name") foreign_key_value = kwargs.get("foreign_key_value") insert_statements = list() - if "id" in stix_object: - bindings["id"] = stix_object["id"] - elif foreign_key_value: - bindings["id"] = foreign_key_value + table = data_sink.tables_dictionary[ canonicalize_table_name( table_name + "_" + dictionary_name, @@ -54,6 +51,10 @@ def generate_insert_information(self, dictionary_name, stix_object, **kwargs): valid_types = stix_object._properties[dictionary_name].valid_types for name, value in stix_object[dictionary_name].items(): bindings = dict() + if "id" in stix_object: + bindings["id"] = stix_object["id"] + elif foreign_key_value: + bindings["id"] = foreign_key_value if not valid_types or len(self.valid_types) == 1: value_binding = "value" elif isinstance(value, int) and IntegerProperty in valid_types: