Skip to content
Snippets Groups Projects

Do not add null fields to the payload when creating model version

Merged Yoann Schneider requested to merge fix-defaults-create-model-version into master
All threads resolved!
2 files
+ 75
59
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -81,7 +81,11 @@ class TrainingMixin(object):
"""
def publish_model_version(
self, model_path: DirPath, model_id: str, tag: str = None, description: str = ""
self,
model_path: DirPath,
model_id: str,
tag: str = None,
description: str = None,
):
"""
This method creates a model archive and its associated hash,
@@ -144,30 +148,29 @@ class TrainingMixin(object):
# Create a new model version with hash and size
try:
payload = {"hash": hash, "size": size, "archive_hash": archive_hash}
if tag:
payload["tag"] = tag
if description:
payload["description"] = description
model_version_details = self.request(
"CreateModelVersion",
id=model_id,
body={
"hash": hash,
"size": size,
"archive_hash": archive_hash,
"tag": tag,
"description": description,
},
body=payload,
)
logger.info(
f"Model version ({model_version_details['id']}) was created successfully"
)
except ErrorResponse as e:
if e.status_code >= 500:
model_version_details = (
e.content.get("hash") if hasattr(e, "content") else None
)
if e.status_code >= 500 or model_version_details is None:
logger.error(f"Failed to create model version: {e.content}")
model_version_details = e.content.get("hash")
raise e
# If the existing model is in Created state, this model is returned as a dict.
# Else an error in a list is returned.
if model_version_details and isinstance(
model_version_details, (list, tuple)
):
if isinstance(model_version_details, (list, tuple)):
logger.error(model_version_details[0])
return
Loading