Merge pull request #1009 from ynput/bugfix/create-instance-data

Create: Required keys in Create Instance data
This commit is contained in:
Jakub Trllo 2024-11-11 17:14:47 +01:00 committed by GitHub
commit ed06d0fd79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -429,11 +429,18 @@ class CreatedInstance:
__immutable_keys = (
"id",
"instance_id",
"product_type",
"productType",
"creator_identifier",
"creator_attributes",
"publish_attributes"
)
# Keys that can be changed, but should not be removed from instance
__required_keys = {
"folderPath": None,
"task": None,
"productName": None,
"active": True,
}
def __init__(
self,
@ -515,6 +522,9 @@ class CreatedInstance:
if data:
self._data.update(data)
for key, default in self.__required_keys.items():
self._data.setdefault(key, default)
if not self._data.get("instance_id"):
self._data["instance_id"] = str(uuid4())
@ -567,6 +577,8 @@ class CreatedInstance:
has_key = key in self._data
output = self._data.pop(key, *args, **kwargs)
if has_key:
if key in self.__required_keys:
self._data[key] = self.__required_keys[key]
self._create_context.instance_values_changed(
self.id, {key: None}
)

View file

@ -296,7 +296,7 @@ class InstanceItem:
return InstanceItem(
instance.id,
instance.creator_identifier,
instance.label,
instance.label or "N/A",
instance.group_label,
instance.product_type,
instance.product_name,