Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cognite_toolkit/_cdf_tk/client/api/instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _validate_page_response(
def _validate_response(self, response: SuccessResponse) -> ResponseItems[InstanceDefinitionId]:
return ResponseItems[InstanceDefinitionId].model_validate_json(response.body)

def create(self, items: Sequence[InstanceRequest]) -> list[InstanceSlimDefinition]:
def create(self, items: Sequence[InstanceRequest], replace: bool = False) -> list[InstanceSlimDefinition]:
"""Create instances in CDF.

Args:
Expand All @@ -95,7 +95,7 @@ def create(self, items: Sequence[InstanceRequest]) -> list[InstanceSlimDefinitio
List of created InstanceSlimDefinition objects.
"""
response_items: list[InstanceSlimDefinition] = []
for response in self._chunk_requests(items, "upsert", self._serialize_items):
for response in self._chunk_requests(items, "upsert", self._serialize_items, extra_body={"replace": replace}):
response_items.extend(PagedResponse[InstanceSlimDefinition].model_validate_json(response.body).items)
return response_items

Expand Down
8 changes: 6 additions & 2 deletions tests_smoke/test_commands/test_migrate_infield.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ def infield_legacy(
for view_id in sorted_views:
instance_batch = to_create_by_view_id[view_id]
try:
_ = client.tool.instances.create(instance_batch)
_ = client.tool.instances.create(instance_batch, replace=True)
except ToolkitAPIError as e:
raise AssertionError(
f"Failed to create instance batch for view {view_id!s}. Error: {e}. Batch: {[item.as_id() for item in instance_batch]}"
) from e
if edges:
try:
_ = client.tool.instances.create(edges)
_ = client.tool.instances.create(edges, replace=True)
Comment on lines -203 to +210
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strictly not necessary, but I added it as it make the set up more robust. Legacy InField is set up exactly the same way each time, it it pre-exist it will be overwritten.

except ToolkitAPIError as e:
raise AssertionError(
f"Failed to create instance batch for edges with no view. Error: {e}. Batch: {[item.as_id() for item in edges]}"
Expand Down Expand Up @@ -355,6 +355,10 @@ def test_migrate_data(
"InField migration failed. Found source space identifier in destination data, indicating that some instances were not migrated correctly."
)

# Cleanup for next run.
destination_node_ids = [node_id for node_ids in destination_by_view_id.values() for node_id in node_ids]
toolkit_client.tool.instances.delete(destination_node_ids)
Comment on lines +358 to +360
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The smoke tests currently failed because, this PR changed the destination data. Since the destination data is not cleaned up, only added to, then, the test started failing.


data_regression.check({"instances": destination_instances})

def _get_destination_nodes(
Expand Down
Loading