Repository: mlte-team/mlte

Issue:
Bug: using force to save artifact does not overwrite existing artifact
The force=true param should overwrite an artifact when writing it. However, the current behavior is that it does not overwrite it, but leaves it as it was.

Discussion:

Fix (patch):
diff --git a/mlte/store/artifact/store_session.py b/mlte/store/artifact/store_session.py
index a9abaae73..296c215c1 100644
--- a/mlte/store/artifact/store_session.py
+++ b/mlte/store/artifact/store_session.py
@@ -173,7 +173,7 @@ def write_artifact(
         """
         artifact_id = artifact.header.identifier
         try:
-            artifact = self.read(artifact_id, (model_id, version_id))
+            _ = self.read(artifact_id, (model_id, version_id))
             if not force:
                 # If it exists and we are not "forcing" (overriting/editing), complain it already exists.
                 raise errors.ErrorAlreadyExists(


Test changes:
diff --git a/test/negotiation/test_artifact.py b/test/negotiation/test_artifact.py
index b6c65c810..f05b0bfe4 100644
--- a/test/negotiation/test_artifact.py
+++ b/test/negotiation/test_artifact.py
@@ -15,6 +15,7 @@
 from mlte.context.context import Context
 from mlte.negotiation import qas
 from mlte.negotiation.artifact import NegotiationCard
+from mlte.negotiation.model import DataDescriptor
 from mlte.negotiation.qas import QASDescriptor
 from mlte.store.artifact.store import ArtifactStore
 from test.fixture.artifact import ArtifactModelFactory
@@ -80,12 +81,17 @@ def test_save_overwrite(
     card = get_sample_negotiation_card()
     card.save_with(ctx, store)
 
+    # Change card.
+    card.data.append(DataDescriptor(description="New data descriptor"))
+
     # Write without `force` fails
     with pytest.raises(errors.ErrorAlreadyExists):
         card.save_with(ctx, store)
 
     # Force write succeeds
-    card.save_with(ctx, store, force=True)
+    read_card_model = card.save_with(ctx, store, force=True)
+    read_card = NegotiationCard.from_model(read_card_model)
+    assert card == read_card
 
 
 def test_qas_id_generation():