Skip to content

Commit

Permalink
Revert "Update from 1297-how-other_subscriptions-can-be-shown-on-the-…
Browse files Browse the repository at this point in the history
…fw-subscription-id (#86)" (#113)

This reverts commit 5937008.
  • Loading branch information
pboers1988 authored Feb 24, 2022
1 parent f0704ec commit 8c1a90f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
66 changes: 22 additions & 44 deletions orchestrator/domain/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ def _find_special_fields(cls: Type) -> None:

if version_info.minor < 10:
annotations = cls.__dict__.get("__annotations__", {})
elif TYPE_CHECKING:
annotations = {}
else:
# Only available in python > 3.10
from inspect import get_annotations
if TYPE_CHECKING:
annotations = {}
else:
# Only available in python > 3.10
from inspect import get_annotations

annotations = get_annotations(cls)
annotations = get_annotations(cls)

for field_name, field_type in annotations.items():
if field_name.startswith("_"):
Expand Down Expand Up @@ -401,10 +402,10 @@ def _save_instances(
saved_instances.extend(saved)
child_instances[product_block_field] = field_instance_list
elif (
not is_optional_type(product_block_field_type)
and not is_union_type(product_block_field_type)
or product_block_models is not None
):
is_optional_type(product_block_field_type) or is_union_type(product_block_field_type)
) and product_block_models is None:
pass
else:
saved, child = product_block_models.save(subscription_id=subscription_id, status=status)
child_instances[product_block_field] = [child]
saved_instances.extend(saved)
Expand Down Expand Up @@ -501,21 +502,6 @@ class ProductBlockModel(DomainModel, metaclass=ProductBlockModelMeta):
owner_subscription_id: UUID
label: Optional[str] = None

def dict(
self,
*,
include: Optional[Any] = None,
exclude: Optional[Any] = None,
by_alias: bool = False,
skip_defaults: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
) -> Dict[str, Any]:
res = super().dict()
res["parent_ids"] = self.parent_ids
return res

def __init_subclass__(
cls,
*,
Expand Down Expand Up @@ -598,7 +584,7 @@ def diff_product_block_in_database(cls) -> Dict[str, Any]:
for product_block_in_model in product_blocks_types_in_model:
missing_data.update(product_block_in_model.diff_product_block_in_database()) # type: ignore

if diff := {
diff = {
k: v
for k, v in {
"missing_product_blocks_in_db": missing_product_blocks_in_db,
Expand All @@ -607,7 +593,9 @@ def diff_product_block_in_database(cls) -> Dict[str, Any]:
"missing_resource_types_in_model": missing_resource_types_in_model,
}.items()
if v
}:
}

if diff:
missing_data[cls.name] = diff

return missing_data
Expand Down Expand Up @@ -787,14 +775,15 @@ def _save_instance_values(
subscription_instance_values.append(
SubscriptionInstanceValueTable(resource_type=resource_type, value=str(val))
)
elif field_name in current_values_dict:
current_value = current_values_dict[field_name][0]
current_value.value = str(value)
subscription_instance_values.append(current_value)
else:
subscription_instance_values.append(
SubscriptionInstanceValueTable(resource_type=resource_type, value=str(value))
)
if field_name in current_values_dict:
current_value = current_values_dict[field_name][0]
current_value.value = str(value)
subscription_instance_values.append(current_value)
else:
subscription_instance_values.append(
SubscriptionInstanceValueTable(resource_type=resource_type, value=str(value))
)
return subscription_instance_values

def _set_instance_domain_model_attrs(
Expand Down Expand Up @@ -904,17 +893,6 @@ def db_model(self) -> SubscriptionInstanceTable:
def parents(self) -> List[SubscriptionInstanceTable]:
return self._db_model.parents

@property
def parent_ids(self) -> List[Optional[Union[UUID, UUIDstr]]]:
p_ids: List[Optional[Union[UUID, UUIDstr]]] = []
if len(self.parents) > 0:
p_ids.extend(
self.parents.col[idx].parent_id # type: ignore
for idx, ob in enumerate(self.parents.col) # type: ignore
if ob.parent_id != self.owner_subscription_id
)
return p_ids

@property
def children(self) -> List[SubscriptionInstanceTable]:
return self._db_model.children
Expand Down
2 changes: 0 additions & 2 deletions test/unit_tests/domain/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,11 @@ def test_save_load(test_product_model, test_product_type_one, test_product_block
"str_field": None,
"subscription_instance_id": mock.ANY,
"owner_subscription_id": mock.ANY,
"parent_ids": mock.ANY,
},
"sub_block_2": None,
"sub_block_list": [],
"owner_subscription_id": mock.ANY,
"subscription_instance_id": mock.ANY,
"parent_ids": mock.ANY,
},
"customer_id": customer_id,
"description": "Desc",
Expand Down

0 comments on commit 8c1a90f

Please sign in to comment.