From 8c1a90f74524c34c948b49e72e6715c6e0a3f279 Mon Sep 17 00:00:00 2001 From: Peter Boers Date: Thu, 24 Feb 2022 11:00:23 +0100 Subject: [PATCH] Revert "Update from 1297-how-other_subscriptions-can-be-shown-on-the-fw-subscription-id (#86)" (#113) This reverts commit 5937008dc2bedbe2b50a33f8e8c7c55783314c07. --- orchestrator/domain/base.py | 66 ++++++++++------------------- test/unit_tests/domain/test_base.py | 2 - 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/orchestrator/domain/base.py b/orchestrator/domain/base.py index c073cefba..b0f3a8d4f 100644 --- a/orchestrator/domain/base.py +++ b/orchestrator/domain/base.py @@ -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("_"): @@ -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) @@ -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, *, @@ -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, @@ -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 @@ -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( @@ -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 diff --git a/test/unit_tests/domain/test_base.py b/test/unit_tests/domain/test_base.py index 05fb46788..686e932e8 100644 --- a/test/unit_tests/domain/test_base.py +++ b/test/unit_tests/domain/test_base.py @@ -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",