From 0ceec606376a008f25a88cd218f0c3c0d29e83dc Mon Sep 17 00:00:00 2001 From: Gayathri Vijayan <66356931+grvijayan@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:47:43 +0200 Subject: [PATCH] fix: sorting options of the `ListInstanceTrustedDomains()` gRPC endpoint (#10172) # Which Problems Are Solved 1. The sorting columns in the gRPC endpoint `ListInstanceTrustedDomains()` are incorrect, and return the following error when invalid sorting options are chosen: ``` Unknown (2) ERROR: missing FROM-clause entry for table "instance_domains" (SQLSTATE 42P01) ``` The sorting columns that are valid to list `instance_trusted_domains` are * `trusted_domain_field_name_unspecified` * `trusted_domain_field_name_domain` * `trusted_domain_field_name_creation_date` However, the currently configured sorting columns are * `domain_field_name_unspecified` * `domain_field_name_domain` * `domain_field_name_primary` * `domain_field_name_generated` * `domain_field_name_creation_date` Configuring the actual columns of `instance_trusted_domains` makes this endpoint **backward incompatible**. Therefore, the fix in this PR is to no longer return an error when an invalid sorting column (non-existing column) is chosen and to sort the results by `creation_date` for invalid sorting columns. 2. This PR also fixes the `sorting_column` included in the responses of both `ListInstanceTrustedDomains()` and `ListInstanceDomains()` endpoints, as they now point to the default option irrespective of the chosen option in the request i.e., * `TRUSTED_DOMAIN_FIELD_NAME_UNSPECIFIED` in case of `ListInstanceTrustedDomains()`, and * `DOMAIN_FIELD_NAME_UNSPECIFIED` in case of `ListInstanceDomains()` # How the Problems Are Solved * Map the sorting columns to valid columns of `instance_trusted_domain` - If the sorting column is not one of the columns, the mapping defaults to `creation_date` * Set the `sorting_column` explicitly (from the request) in the `ListInstanceDomainsResponse` and `ListInstanceTrustedDomainsResponse` # Additional Changes A small fix to return the chosen `sorting_column` in the responses of the `ListInstanceTrustedDomains()` and `ListInstanceDomains()` endpoints # Additional Context - Closes #9839 --- internal/api/grpc/admin/instance.go | 2 ++ internal/api/grpc/admin/instance_converter.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/api/grpc/admin/instance.go b/internal/api/grpc/admin/instance.go index 74f1576ae..a7b0316ec 100644 --- a/internal/api/grpc/admin/instance.go +++ b/internal/api/grpc/admin/instance.go @@ -30,6 +30,7 @@ func (s *Server) ListInstanceDomains(ctx context.Context, req *admin_pb.ListInst } return &admin_pb.ListInstanceDomainsResponse{ Result: instance_grpc.DomainsToPb(domains.Domains), + SortingColumn: req.SortingColumn, Details: object.ToListDetails( domains.Count, domains.Sequence, @@ -49,6 +50,7 @@ func (s *Server) ListInstanceTrustedDomains(ctx context.Context, req *admin_pb.L } return &admin_pb.ListInstanceTrustedDomainsResponse{ Result: instance_grpc.TrustedDomainsToPb(domains.Domains), + SortingColumn: req.SortingColumn, Details: object.ToListDetails( domains.Count, domains.Sequence, diff --git a/internal/api/grpc/admin/instance_converter.go b/internal/api/grpc/admin/instance_converter.go index 397845c9e..603d544cb 100644 --- a/internal/api/grpc/admin/instance_converter.go +++ b/internal/api/grpc/admin/instance_converter.go @@ -51,8 +51,23 @@ func ListInstanceTrustedDomainsRequestToModel(req *admin_pb.ListInstanceTrustedD Offset: offset, Limit: limit, Asc: asc, - SortingColumn: fieldNameToInstanceDomainColumn(req.SortingColumn), + SortingColumn: fieldNameToInstanceTrustedDomainColumn(req.SortingColumn), }, Queries: queries, }, nil } + +func fieldNameToInstanceTrustedDomainColumn(fieldName instance.DomainFieldName) query.Column { + switch fieldName { + case instance.DomainFieldName_DOMAIN_FIELD_NAME_DOMAIN: + return query.InstanceTrustedDomainDomainCol + case instance.DomainFieldName_DOMAIN_FIELD_NAME_CREATION_DATE: + return query.InstanceTrustedDomainCreationDateCol + case instance.DomainFieldName_DOMAIN_FIELD_NAME_UNSPECIFIED, + instance.DomainFieldName_DOMAIN_FIELD_NAME_PRIMARY, + instance.DomainFieldName_DOMAIN_FIELD_NAME_GENERATED: + return query.InstanceTrustedDomainCreationDateCol + default: + return query.Column{} + } +}