mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
Making labels additive and not adding a many item to config if already in parent
This commit is contained in:
committed by
Alan Rominger
parent
68e11d2b81
commit
e076f1ee2a
@@ -976,11 +976,11 @@ class LaunchTimeConfigBase(BaseModel):
|
|||||||
if isinstance(field, models.ManyToManyField):
|
if isinstance(field, models.ManyToManyField):
|
||||||
if not self.pk:
|
if not self.pk:
|
||||||
continue # unsaved object can't have related many-to-many
|
continue # unsaved object can't have related many-to-many
|
||||||
prompt_val = set(getattr(self, prompt_name).all())
|
prompt_values = list(getattr(self, prompt_name).all())
|
||||||
if len(prompt_val) > 0:
|
# Many to manys can't distinguish between None and []
|
||||||
# We used to return a set but that will cause issues with order for ordered fields (like instance_groups)
|
# Because of this, from a config perspective, we assume [] is none and we don't save [] into the config
|
||||||
# So instead we will return an array of items
|
if len(prompt_values) > 0:
|
||||||
data[prompt_name] = [item for item in getattr(self, prompt_name).all()]
|
data[prompt_name] = prompt_values
|
||||||
elif prompt_name == 'extra_vars':
|
elif prompt_name == 'extra_vars':
|
||||||
if self.extra_vars:
|
if self.extra_vars:
|
||||||
if display:
|
if display:
|
||||||
|
|||||||
@@ -1007,8 +1007,11 @@ class UnifiedJob(
|
|||||||
# Here we are doing a loop to make sure we preserve order in case this is a Ordered field
|
# Here we are doing a loop to make sure we preserve order in case this is a Ordered field
|
||||||
job_item = kwargs.get(field_name, [])
|
job_item = kwargs.get(field_name, [])
|
||||||
if job_item:
|
if job_item:
|
||||||
|
parent_items = getattr(parent, field_name, []).all()
|
||||||
for item in job_item:
|
for item in job_item:
|
||||||
getattr(config, field_name).add(item)
|
# Do not include this item in the config if its in the parent
|
||||||
|
if item not in parent_items:
|
||||||
|
getattr(config, field_name).add(item)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|||||||
@@ -531,13 +531,16 @@ def copy_m2m_relationships(obj1, obj2, fields, kwargs=None):
|
|||||||
src_field_value = getattr(obj1, field_name)
|
src_field_value = getattr(obj1, field_name)
|
||||||
if kwargs and field_name in kwargs:
|
if kwargs and field_name in kwargs:
|
||||||
override_field_val = kwargs[field_name]
|
override_field_val = kwargs[field_name]
|
||||||
# TODO: Should we spike this our or just put the for loop inside the next if and make everything respect order?
|
|
||||||
if field_name == 'instance_groups':
|
if field_name == 'instance_groups':
|
||||||
# instance_groups are a list but we need to preserve the order
|
# instance_groups are a list but we need to preserve the order
|
||||||
for ig_id in override_field_val:
|
for ig_id in override_field_val:
|
||||||
getattr(obj2, field_name).add(ig_id)
|
getattr(obj2, field_name).add(ig_id)
|
||||||
continue
|
continue
|
||||||
if isinstance(override_field_val, (set, list, QuerySet)):
|
if isinstance(override_field_val, (set, list, QuerySet)):
|
||||||
|
# Labels are additive so we are going to add any src labels in addition to the override labels
|
||||||
|
if field_name == 'labels':
|
||||||
|
for jt_label in src_field_value.all():
|
||||||
|
getattr(obj2, field_name).add(jt_label.id)
|
||||||
getattr(obj2, field_name).add(*override_field_val)
|
getattr(obj2, field_name).add(*override_field_val)
|
||||||
continue
|
continue
|
||||||
if override_field_val.__class__.__name__ == 'ManyRelatedManager':
|
if override_field_val.__class__.__name__ == 'ManyRelatedManager':
|
||||||
|
|||||||
Reference in New Issue
Block a user