77
88import time
99from collections .abc import Callable
10+ from copy import deepcopy
1011from typing import Any
1112
1213from elastic_transport import ObjectApiResponse
@@ -211,7 +212,7 @@ def prepare_integration_mappings( # noqa: PLR0913
211212 f"Removing parent field from schema for ES|QL validation."
212213 )
213214 delete_nested_key_from_dict (stream_mappings , field_name )
214- utils .combine_dicts (integration_mappings , stream_mappings )
215+ utils .combine_dicts (integration_mappings , deepcopy ( stream_mappings ) )
215216 index_lookup [f"{ integration } -{ stream } " ] = stream_mappings
216217
217218 return integration_mappings , index_lookup
@@ -298,7 +299,7 @@ def find_nested_multifields(mapping: dict[str, Any], path: str = "") -> list[Any
298299
299300def find_flattened_fields_with_subfields (mapping : dict [str , Any ], path : str = "" ) -> list [str ]:
300301 """Recursively search for fields of type 'flattened' that have a 'fields' key in Elasticsearch mappings."""
301- flattened_fields_with_subfields = []
302+ flattened_fields_with_subfields : list [ str ] = []
302303
303304 for field , properties in mapping .items ():
304305 current_path = f"{ path } .{ field } " if path else field
@@ -314,7 +315,7 @@ def find_flattened_fields_with_subfields(mapping: dict[str, Any], path: str = ""
314315 find_flattened_fields_with_subfields (properties ["properties" ], current_path ) # type: ignore[reportUnknownVariableType]
315316 )
316317
317- return flattened_fields_with_subfields # type: ignore[reportUnknownVariableType]
318+ return flattened_fields_with_subfields
318319
319320
320321def get_ecs_schema_mappings (current_version : Version ) -> dict [str , Any ]:
@@ -366,8 +367,8 @@ def prepare_mappings( # noqa: PLR0913
366367
367368 # Combine existing and integration mappings into a single mapping dict
368369 combined_mappings : dict [str , Any ] = {}
369- utils .combine_dicts (combined_mappings , existing_mappings )
370- utils .combine_dicts (combined_mappings , integration_mappings )
370+ utils .combine_dicts (combined_mappings , deepcopy ( existing_mappings ) )
371+ utils .combine_dicts (combined_mappings , deepcopy ( integration_mappings ) )
371372
372373 # Load non-ecs schema and convert to index mapping format (nested schema)
373374 non_ecs_mapping : dict [str , Any ] = {}
@@ -382,7 +383,7 @@ def prepare_mappings( # noqa: PLR0913
382383 ecs_schema = get_ecs_schema_mappings (current_version )
383384
384385 index_lookup .update ({"rule-ecs-index" : ecs_schema })
385- utils .combine_dicts (combined_mappings , ecs_schema )
386+ utils .combine_dicts (combined_mappings , deepcopy ( ecs_schema ) )
386387
387388 if not combined_mappings and not non_ecs_mapping and not ecs_schema :
388389 raise ValueError ("No mappings found" )
0 commit comments