diff --git a/apps/backend/subscription/handler.py b/apps/backend/subscription/handler.py index 1c4ef456c..ef81ec38d 100644 --- a/apps/backend/subscription/handler.py +++ b/apps/backend/subscription/handler.py @@ -18,7 +18,7 @@ from django.conf import settings from django.core.cache import cache -from django.db.models import Max, Q, QuerySet +from django.db.models import Max, Q, QuerySet, Value from django.utils.translation import get_language from django.utils.translation import ugettext as _ @@ -579,7 +579,7 @@ def instance_status(subscription_id_list: List[int], show_task_detail: bool) -> subscription_instance_record: Dict[int, Dict[str, models.SubscriptionInstanceRecord]] = defaultdict(dict) instance_records = [] for instance_record in models.SubscriptionInstanceRecord.objects.filter( - subscription_id__in=subscription_id_list, is_latest=True + subscription_id__in=subscription_id_list, is_latest=Value(1) ): subscription_instance_record[instance_record.subscription_id][instance_record.instance_id] = instance_record instance_records.append(instance_record) diff --git a/apps/backend/subscription/views.py b/apps/backend/subscription/views.py index 69d828549..9d13b2cab 100644 --- a/apps/backend/subscription/views.py +++ b/apps/backend/subscription/views.py @@ -18,7 +18,7 @@ from django.core.cache import caches from django.db import transaction -from django.db.models import Q +from django.db.models import Q, Value from django.utils.translation import get_language from django.utils.translation import gettext_lazy as _ from drf_yasg.utils import swagger_auto_schema @@ -779,8 +779,14 @@ def query_host_policy(self, request): host = models.Host.objects.get(bk_host_id=bk_host_id) subscription_records = models.SubscriptionInstanceRecord.objects.filter( - instance_id__endswith="host|{}".format(host.bk_host_id), - is_latest=True, + instance_id=tools.create_node_id( + { + "node_type": models.Subscription.NodeType.INSTANCE, + "object_type": models.Subscription.ObjectType.HOST, + "bk_host_id": host.bk_host_id, + } + ), + is_latest=Value(1), ).values("subscription_id", "update_time", "instance_id", "task_id", "status") sub_id__sub_record_map = {