Prune empty values before creating instance
This commit is contained in:
parent
d5ad664bca
commit
6c6fb06a01
1 changed files with 26 additions and 0 deletions
|
@ -305,6 +305,31 @@ def validate_api_definition(value):
|
||||||
return validate_dict(value, required_fields)
|
return validate_dict(value, required_fields)
|
||||||
|
|
||||||
|
|
||||||
|
def prune_empty_data(data):
|
||||||
|
"""
|
||||||
|
Recursively remove empty values from dictionaries and lists.
|
||||||
|
Empty values include: None, empty strings, empty lists, empty dicts.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def is_empty(value):
|
||||||
|
return value is None or value == "" or value == [] or value == {}
|
||||||
|
|
||||||
|
if isinstance(data, dict):
|
||||||
|
return {
|
||||||
|
key: pruned_value
|
||||||
|
for key, value in data.items()
|
||||||
|
if not is_empty(pruned_value := prune_empty_data(value))
|
||||||
|
}
|
||||||
|
elif isinstance(data, list):
|
||||||
|
return [
|
||||||
|
pruned_item
|
||||||
|
for item in data
|
||||||
|
if not is_empty(pruned_item := prune_empty_data(item))
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class ServiceDefinition(ServalaModelMixin, models.Model):
|
class ServiceDefinition(ServalaModelMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Configuration/service implementation: contains information on which
|
Configuration/service implementation: contains information on which
|
||||||
|
@ -588,6 +613,7 @@ class ServiceInstance(ServalaModelMixin, models.Model):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
spec_data = spec_data or {}
|
spec_data = spec_data or {}
|
||||||
|
spec_data = prune_empty_data(spec_data)
|
||||||
if "writeConnectionSecretToRef" not in spec_data:
|
if "writeConnectionSecretToRef" not in spec_data:
|
||||||
spec_data["writeConnectionSecretToRef"] = {}
|
spec_data["writeConnectionSecretToRef"] = {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue