CVE-2023-41891: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: FlyteAdmin is the control plane for Flyte responsible for managing entities and administering workflow executions. Prior to version 1.1.124, list endpoints on FlyteAdmin have a SQL vulnerability where a malicious user can send a REST request with custom SQL statements as list filters. The attacker needs to have access to the FlyteAdmin installation, typically either behind a VPN or authentication. Version 1.1.124 contains a patch for this issue.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 8.8
Published: 2023-10-30T19:15Z
Repository: https://github.com/flyteorg/flyteadmin
Language: Go
Files changed: pkg/clusterresource/impl/admin_service_data_provider.go, pkg/clusterresource/impl/shared.go, pkg/common/sorting.go, pkg/common/sorting_test.go, pkg/manager/impl/description_entity_manager.go, pkg/manager/impl/execution_manager.go, pkg/manager/impl/execution_manager_test.go, pkg/manager/impl/launch_plan_manager.go, pkg/manager/impl/named_entity_manager.go, pkg/manager/impl/node_execution_manager.go, pkg/manager/impl/node_execution_manager_test.go, pkg/manager/impl/project_manager.go, pkg/manager/impl/signal_manager.go, pkg/manager/impl/task_execution_manager.go, pkg/manager/impl/task_manager.go, pkg/manager/impl/util/filters.go, pkg/manager/impl/util/filters_test.go, pkg/manager/impl/workflow_manager.go, pkg/repositories/gormimpl/common.go, pkg/repositories/gormimpl/description_entity_repo.go, pkg/repositories/gormimpl/execution_repo.go, pkg/repositories/gormimpl/execution_repo_test.go, pkg/repositories/gormimpl/launch_plan_repo.go, pkg/repositories/gormimpl/launch_plan_repo_test.go, pkg/repositories/gormimpl/named_entity_repo.go, pkg/repositories/gormimpl/named_entity_repo_test.go, pkg/repositories/gormimpl/node_execution_event_repo.go, pkg/repositories/gormimpl/node_execution_repo.go, pkg/repositories/gormimpl/node_execution_repo_test.go, pkg/repositories/gormimpl/project_repo.go, pkg/repositories/gormimpl/project_repo_test.go, pkg/repositories/gormimpl/resource_repo_test.go, pkg/repositories/gormimpl/signal_repo.go, pkg/repositories/gormimpl/task_execution_repo.go, pkg/repositories/gormimpl/task_execution_repo_test.go, pkg/repositories/gormimpl/task_repo.go, pkg/repositories/gormimpl/task_repo_test.go, pkg/repositories/gormimpl/workflow_repo.go, pkg/repositories/gormimpl/workflow_repo_test.go, pkg/repositories/models/base_model.go, pkg/repositories/models/description_entity.go, pkg/repositories/models/execution.go, pkg/repositories/models/launch_plan.go, pkg/repositories/models/named_entity.go, pkg/repositories/models/node_execution.go, pkg/repositories/models/node_execution_event.go, pkg/repositories/models/project.go, pkg/repositories/models/signal.go, pkg/repositories/models/task.go, pkg/repositories/models/task_execution.go, pkg/repositories/models/workflow.go
Commit date: 2023-08-31 14:21:05 -0700
Commit message: Merge pull request from GHSA-r847-6w6h-r8g4

* Fix list filters

* Fix sort keys

* split into 2 maps

* move columns to models

* move columns to models
Diff: diff --git a/pkg/clusterresource/impl/admin_service_data_provider.go b/pkg/clusterresource/impl/admin_service_data_provider.go
index 41d92b2..1818d25 100644
--- a/pkg/clusterresource/impl/admin_service_data_provider.go
+++ b/pkg/clusterresource/impl/admin_service_data_provider.go
@@ -2,13 +2,16 @@ package impl
 
 import (
 	"context"
 	"fmt"
 
-	"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service"
+
+	"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/common"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 )
 
 // Implementation of an interfaces.FlyteAdminDataProvider which fetches data using a flyteadmin service client
 type serviceAdminProvider struct {
 	adminClient service.AdminServiceClient
@@ -30,10 +33,17 @@ func (p serviceAdminProvider) GetClusterResourceAttributes(ctx context.Context,
 	return nil, NewMissingEntityError("cluster resource attributes")
 }
 
 var activeProjectsFilter = fmt.Sprintf("ne(state,%d)", admin.Project_ARCHIVED)
 
+var descCreatedAtSortParam = admin.Sort{
+	Direction: admin.Sort_DESCENDING,
+	Key:       "created_at",
+}
+
+var descCreatedAtSortDBParam, _ = common.NewSortParameter(&descCreatedAtSortParam, models.ProjectColumns)
+
 func (p serviceAdminProvider) GetProjects(ctx context.Context) (*admin.Projects, error) {
 	projects := make([]*admin.Project, 0)
 	listReq := &admin.ProjectListRequest{
 		Limit:   100,
 		Filters: activeProjectsFilter,
diff --git a/pkg/clusterresource/impl/shared.go b/pkg/clusterresource/impl/shared.go
index 6ba0785..7c911bc 100644
--- a/pkg/clusterresource/impl/shared.go
+++ b/pkg/clusterresource/impl/shared.go
@@ -1,19 +1,10 @@
 package impl
 
 import (
-	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"google.golang.org/grpc/codes"
 )
 
 func NewMissingEntityError(entity string) error {
 	return errors.NewFlyteAdminErrorf(codes.NotFound, "Failed to find [%s]", entity)
 }
-
-var descCreatedAtSortParam = admin.Sort{
-	Direction: admin.Sort_DESCENDING,
-	Key:       "created_at",
-}
-
-var descCreatedAtSortDBParam, _ = common.NewSortParameter(descCreatedAtSortParam)
diff --git a/pkg/common/sorting.go b/pkg/common/sorting.go
index c4922d0..7057a2a 100644
--- a/pkg/common/sorting.go
+++ b/pkg/common/sorting.go
@@ -1,9 +1,10 @@
 package common
 
 import (
 	"fmt"
+	"k8s.io/apimachinery/pkg/util/sets"
 
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"google.golang.org/grpc/codes"
 )
@@ -21,17 +22,26 @@ type sortParamImpl struct {
 
 func (s *sortParamImpl) GetGormOrderExpr() string {
 	return s.gormOrderExpression
 }
 
-func NewSortParameter(sort admin.Sort) (SortParameter, error) {
+func NewSortParameter(sort *admin.Sort, allowed sets.String) (SortParameter, error) {
+	if sort == nil {
+		return nil, nil
+	}
+
+	key := sort.Key
+	if !allowed.Has(key) {
+		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid sort key '%s'", key)
+	}
+
 	var gormOrderExpression string
 	switch sort.Direction {
 	case admin.Sort_DESCENDING:
-		gormOrderExpression = fmt.Sprintf(gormDescending, sort.Key)
+		gormOrderExpression = fmt.Sprintf(gormDescending, key)
 	case admin.Sort_ASCENDING:
-		gormOrderExpression = fmt.Sprintf(gormAscending, sort.Key)
+		gormOrderExpression = fmt.Sprintf(gormAscending, key)
 	default:
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid sort order specified: %v", sort)
 	}
 	return &sortParamImpl{
 		gormOrderExpression: gormOrderExpression,
diff --git a/pkg/common/sorting_test.go b/pkg/common/sorting_test.go
index 20cb69f..2918199 100644
--- a/pkg/common/sorting_test.go
+++ b/pkg/common/sorting_test.go
@@ -1,26 +1,55 @@
 package common
 
 import (
 	"testing"
 
+	"k8s.io/apimachinery/pkg/util/sets"
+
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/stretchr/testify/assert"
 )
 
+func TestSortParameter_Nil(t *testing.T) {
+	sortParameter, err := NewSortParameter(nil, nil)
+
+	assert.NoError(t, err)
+	assert.Nil(t, sortParameter)
+}
+
+func TestSortParameter_InvalidSortKey(t *testing.T) {
+	_, err := NewSortParameter(&admin.Sort{
+		Direction: admin.Sort_ASCENDING,
+		Key:       "wrong",
+	}, sets.NewString("name"))
+
+	assert.EqualError(t, err, "invalid sort key 'wrong'")
+}
+
+func TestSortParameter_InvalidSortDirection(t *testing.T) {
+	_, err := NewSortParameter(&admin.Sort{
+		Direction: 2,
+		Key:       "name",
+	}, sets.NewString("name"))
+
+	assert.EqualError(t, err, `invalid sort order specified: key:"name" direction:2 `)
+}
+
 func TestSortParameter_Ascending(t *testing.T) {
-	sortParameter, err := NewSortParameter(admin.Sort{
+	sortParameter, err := NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_ASCENDING,
 		Key:       "name",
-	})
-	assert.Nil(t, err)
+	}, sets.NewString("name"))
+
+	assert.NoError(t, err)
 	assert.Equal(t, "name asc", sortParameter.GetGormOrderExpr())
 }
 
 func TestSortParameter_Descending(t *testing.T) {
-	sortParameter, err := NewSortParameter(admin.Sort{
+	sortParameter, err := NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
 		Key:       "project",
-	})
-	assert.Nil(t, err)
+	}, sets.NewString("project"))
+
+	assert.NoError(t, err)
 	assert.Equal(t, "project desc", sortParameter.GetGormOrderExpr())
 }
diff --git a/pkg/manager/impl/description_entity_manager.go b/pkg/manager/impl/description_entity_manager.go
index 3dcd7ab..91e5398 100644
--- a/pkg/manager/impl/description_entity_manager.go
+++ b/pkg/manager/impl/description_entity_manager.go
@@ -2,26 +2,26 @@ package impl
 
 import (
 	"context"
 	"strconv"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	"github.com/flyteorg/flytestdlib/contextutils"
+	"github.com/flyteorg/flytestdlib/logger"
+	"github.com/flyteorg/flytestdlib/promutils"
+	"google.golang.org/grpc/codes"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
-
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flytestdlib/contextutils"
-	"github.com/flyteorg/flytestdlib/logger"
-	"github.com/flyteorg/flytestdlib/promutils"
-	"google.golang.org/grpc/codes"
 )
 
 type DescriptionEntityMetrics struct {
 	Scope promutils.Scope
 }
@@ -63,17 +63,16 @@ func (d *DescriptionEntityManager) ListDescriptionEntity(ctx context.Context, re
 	}, common.ResourceTypeToEntity[request.ResourceType])
 	if err != nil {
 		logger.Error(ctx, "failed to get database filter")
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.DescriptionEntityColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListWorkflows", request.Token)
 	}
diff --git a/pkg/manager/impl/execution_manager.go b/pkg/manager/impl/execution_manager.go
index e881ef1..bd57d4f 100644
--- a/pkg/manager/impl/execution_manager.go
+++ b/pkg/manager/impl/execution_manager.go
@@ -4,53 +4,45 @@ import (
 	"context"
 	"fmt"
 	"strconv"
 	"time"
 
-	"github.com/flyteorg/flytestdlib/promutils/labeled"
-
-	"github.com/flyteorg/flyteadmin/plugins"
-
+	"github.com/benbjohnson/clock"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
-
-	"github.com/flyteorg/flyteadmin/auth"
-
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"
-
-	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
 	"github.com/flyteorg/flytestdlib/contextutils"
+	"github.com/flyteorg/flytestdlib/logger"
 	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/promutils/labeled"
+	"github.com/flyteorg/flytestdlib/storage"
+	"github.com/golang/protobuf/proto"
 	"github.com/golang/protobuf/ptypes"
 	"github.com/golang/protobuf/ptypes/timestamp"
 	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
-	"github.com/flyteorg/flyteadmin/pkg/common"
-
-	"github.com/flyteorg/flytestdlib/logger"
-	"github.com/flyteorg/flytestdlib/storage"
-
+	"github.com/flyteorg/flyteadmin/auth"
 	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
 	eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/async/notifications"
 	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/common"
+	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/executions"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repositoryInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
 	workflowengineInterfaces "github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"google.golang.org/grpc/codes"
-
-	"github.com/benbjohnson/clock"
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
-	"github.com/golang/protobuf/proto"
+	"github.com/flyteorg/flyteadmin/plugins"
 )
 
 const childContainerQueueKey = "child_queue"
 
 // Map of [project] -> map of [domain] -> stop watch
@@ -1432,16 +1424,14 @@ func (m *ExecutionManager) ListExecutions(
 		RequestFilters: request.Filters,
 	}, common.Execution)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.ExecutionColumns)
+	if err != nil {
+		return nil, err
 	}
 
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid pagination token %s for ListExecutions",
diff --git a/pkg/manager/impl/execution_manager_test.go b/pkg/manager/impl/execution_manager_test.go
index 34d436e..38bac0d 100644
--- a/pkg/manager/impl/execution_manager_test.go
+++ b/pkg/manager/impl/execution_manager_test.go
@@ -1,68 +1,58 @@
 package impl
 
 import (
 	"context"
 	"errors"
+	"fmt"
 	"strings"
 	"testing"
-
-	"github.com/flyteorg/flyteadmin/plugins"
-
-	"google.golang.org/grpc/status"
-
-	"google.golang.org/protobuf/types/known/timestamppb"
+	"time"
 
 	"github.com/benbjohnson/clock"
-	"github.com/flyteorg/flyteadmin/pkg/common"
-	commonTestUtils "github.com/flyteorg/flyteadmin/pkg/common/testutils"
-	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/executions"
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
-	managerInterfaces "github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
-	managerMocks "github.com/flyteorg/flyteadmin/pkg/manager/mocks"
-	"github.com/flyteorg/flyteadmin/pkg/runtime"
 	"github.com/flyteorg/flyteidl/clients/go/coreutils"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/event"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/storage"
 	"github.com/gogo/protobuf/jsonpb"
+	"github.com/golang/protobuf/proto"
 	"github.com/golang/protobuf/ptypes"
+	"github.com/golang/protobuf/ptypes/wrappers"
+	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/mock"
 	"google.golang.org/grpc/codes"
-
+	"google.golang.org/grpc/status"
+	"google.golang.org/protobuf/types/known/timestamppb"
 	"k8s.io/apimachinery/pkg/api/resource"
-
-	eventWriterMocks "github.com/flyteorg/flyteadmin/pkg/async/events/mocks"
 	"k8s.io/apimachinery/pkg/util/sets"
 
 	"github.com/flyteorg/flyteadmin/auth"
-
-	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
-
-	"github.com/flyteorg/flytestdlib/storage"
-
-	"time"
-
-	"fmt"
-
+	eventWriterMocks "github.com/flyteorg/flyteadmin/pkg/async/events/mocks"
 	notificationMocks "github.com/flyteorg/flyteadmin/pkg/async/notifications/mocks"
+	"github.com/flyteorg/flyteadmin/pkg/common"
+	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
+	commonTestUtils "github.com/flyteorg/flyteadmin/pkg/common/testutils"
 	dataMocks "github.com/flyteorg/flyteadmin/pkg/data/mocks"
+	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/executions"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"
+	managerInterfaces "github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
+	managerMocks "github.com/flyteorg/flyteadmin/pkg/manager/mocks"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
+	"github.com/flyteorg/flyteadmin/pkg/runtime"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
 	runtimeIFaceMocks "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces/mocks"
 	runtimeMocks "github.com/flyteorg/flyteadmin/pkg/runtime/mocks"
 	workflowengineInterfaces "github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
 	workflowengineMocks "github.com/flyteorg/flyteadmin/pkg/workflowengine/mocks"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-	"github.com/golang/protobuf/proto"
-	"github.com/golang/protobuf/ptypes/wrappers"
-	"github.com/stretchr/testify/assert"
+	"github.com/flyteorg/flyteadmin/plugins"
 )
 
 var spec = testutils.GetExecutionRequest().Spec
 var specBytes, _ = proto.Marshal(spec)
 var phase = core.WorkflowExecution_RUNNING.String()
@@ -2977,11 +2967,11 @@ func TestListExecutions(t *testing.T) {
 		}
 		assert.True(t, projectFilter, "Missing project equality filter")
 		assert.True(t, domainFilter, "Missing domain equality filter")
 		assert.False(t, nameFilter, "Included name equality filter")
 		assert.Equal(t, limit, input.Limit)
-		assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
+		assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
 		assert.Equal(t, 2, input.Offset)
 		assert.EqualValues(t, map[common.Entity]bool{
 			common.Execution: true,
 		}, input.JoinTableEntities)
 		return interfaces.ExecutionCollectionOutput{
@@ -3025,11 +3015,11 @@ func TestListExecutions(t *testing.T) {
 			Domain:  domainValue,
 		},
 		Limit: limit,
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 		Token: "2",
 	})
 	assert.NoError(t, err)
 	assert.NotNil(t, executionList)
@@ -3963,11 +3953,11 @@ func TestListExecutions_LegacyModel(t *testing.T) {
 		}
 		assert.True(t, projectFilter, "Missing project equality filter")
 		assert.True(t, domainFilter, "Missing domain equality filter")
 		assert.False(t, nameFilter, "Included name equality filter")
 		assert.Equal(t, limit, input.Limit)
-		assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
+		assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
 		assert.Equal(t, 2, input.Offset)
 		return interfaces.ExecutionCollectionOutput{
 			Executions: []models.Execution{
 				{
 					BaseModel: models.BaseModel{
@@ -4008,11 +3998,11 @@ func TestListExecutions_LegacyModel(t *testing.T) {
 			Domain:  domainValue,
 		},
 		Limit: limit,
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 		Token: "2",
 	})
 	assert.NoError(t, err)
 	assert.NotNil(t, executionList)
diff --git a/pkg/manager/impl/launch_plan_manager.go b/pkg/manager/impl/launch_plan_manager.go
index f2192b7..5e1c3fb 100644
--- a/pkg/manager/impl/launch_plan_manager.go
+++ b/pkg/manager/impl/launch_plan_manager.go
@@ -3,32 +3,29 @@ package impl
 import (
 	"bytes"
 	"context"
 	"strconv"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/contextutils"
-
+	"github.com/flyteorg/flytestdlib/logger"
 	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/golang/protobuf/proto"
 	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
 	scheduleInterfaces "github.com/flyteorg/flyteadmin/pkg/async/schedule/interfaces"
-
-	"github.com/flyteorg/flytestdlib/logger"
-
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"github.com/golang/protobuf/proto"
-	"google.golang.org/grpc/codes"
 )
 
 type launchPlanMetrics struct {
 	Scope                 promutils.Scope
 	FailedScheduleUpdates prometheus.Counter
@@ -406,17 +403,15 @@ func (m *LaunchPlanManager) ListLaunchPlans(ctx context.Context, request admin.R
 	}, common.LaunchPlan)
 	if err != nil {
 		return nil, err
 	}
 
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListLaunchPlans", request.Token)
 	}
@@ -461,17 +456,15 @@ func (m *LaunchPlanManager) ListActiveLaunchPlans(ctx context.Context, request a
 	filters, err := util.ListActiveLaunchPlanVersionsFilters(request.Project, request.Domain)
 	if err != nil {
 		return nil, err
 	}
 
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListActiveLaunchPlans", request.Token)
 	}
@@ -512,17 +505,16 @@ func (m *LaunchPlanManager) ListLaunchPlanIds(ctx context.Context, request admin
 		Domain:  request.Domain,
 	}, common.LaunchPlan)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid pagination token %s", request.Token)
 	}
 	listLaunchPlansInput := repoInterfaces.ListResourceInput{
diff --git a/pkg/manager/impl/named_entity_manager.go b/pkg/manager/impl/named_entity_manager.go
index d65f5ec..9c29910 100644
--- a/pkg/manager/impl/named_entity_manager.go
+++ b/pkg/manager/impl/named_entity_manager.go
@@ -3,27 +3,26 @@ package impl
 import (
 	"context"
 	"strconv"
 	"strings"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
 	"github.com/flyteorg/flytestdlib/contextutils"
+	"github.com/flyteorg/flytestdlib/logger"
+	"github.com/flyteorg/flytestdlib/promutils"
+	"google.golang.org/grpc/codes"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
-	"google.golang.org/grpc/codes"
-
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flytestdlib/logger"
-	"github.com/flyteorg/flytestdlib/promutils"
 )
 
 const state = "state"
 
 // System-generated workflows are meant to be hidden from the user by default. Therefore we always only show
@@ -117,17 +116,16 @@ func (m *NamedEntityManager) ListNamedEntities(ctx context.Context, request admi
 	// has an entry, and therefore the default state value '0' (active), should be assumed.
 	filters, err := m.getQueryFilters(request.ResourceType, request.Filters)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.NamedEntityColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListNamedEntities", request.Token)
 	}
diff --git a/pkg/manager/impl/node_execution_manager.go b/pkg/manager/impl/node_execution_manager.go
index bcc4362..50e33b7 100644
--- a/pkg/manager/impl/node_execution_manager.go
+++ b/pkg/manager/impl/node_execution_manager.go
@@ -1,46 +1,37 @@
 package impl
 
 import (
 	"context"
+	"fmt"
 	"strconv"
 
-	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
-
-	"github.com/flyteorg/flytestdlib/promutils/labeled"
-
-	eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/interfaces"
-
-	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
-	"github.com/golang/protobuf/proto"
-
-	"github.com/flyteorg/flytestdlib/storage"
-
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/contextutils"
-
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
+	"github.com/flyteorg/flytestdlib/logger"
 	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/promutils/labeled"
+	"github.com/flyteorg/flytestdlib/storage"
+	"github.com/golang/protobuf/proto"
 	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
-	"github.com/flyteorg/flytestdlib/logger"
-
+	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
+	eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/interfaces"
+	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/common"
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
-
-	"fmt"
-
 	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"google.golang.org/grpc/codes"
 )
 
 type nodeExecutionMetrics struct {
 	Scope                      promutils.Scope
 	ActiveNodeExecutions       prometheus.Gauge
@@ -376,17 +367,16 @@ func (m *NodeExecutionManager) listNodeExecutions(
 
 	filters, err := util.AddRequestFilters(requestFilters, common.NodeExecution, identifierFilters)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if sortBy != nil {
-		sortParameter, err = common.NewSortParameter(*sortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(sortBy, models.NodeExecutionColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(requestToken)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListNodeExecutions", requestToken)
 	}
diff --git a/pkg/manager/impl/node_execution_manager_test.go b/pkg/manager/impl/node_execution_manager_test.go
index 1348803..9f32607 100644
--- a/pkg/manager/impl/node_execution_manager_test.go
+++ b/pkg/manager/impl/node_execution_manager_test.go
@@ -13,28 +13,30 @@ import (
 
 	genModel "github.com/flyteorg/flyteadmin/pkg/repositories/gen/models"
 
 	eventWriterMocks "github.com/flyteorg/flyteadmin/pkg/async/events/mocks"
 
-	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"
 	"github.com/flyteorg/flytestdlib/storage"
 
-	"github.com/flyteorg/flyteadmin/pkg/common"
-	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
-	dataMocks "github.com/flyteorg/flyteadmin/pkg/data/mocks"
-	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
-	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
-	repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks"
-	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
+	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"
+
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/event"
 	mockScope "github.com/flyteorg/flytestdlib/promutils"
 	"github.com/golang/protobuf/proto"
 	"github.com/golang/protobuf/ptypes"
 	"github.com/stretchr/testify/assert"
 	"google.golang.org/grpc/codes"
+
+	"github.com/flyteorg/flyteadmin/pkg/common"
+	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
+	dataMocks "github.com/flyteorg/flyteadmin/pkg/data/mocks"
+	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 )
 
 var occurredAt = time.Now().UTC()
 var occurredAtProto, _ = ptypes.TimestampProto(occurredAt)
 
@@ -805,11 +807,11 @@ func TestListNodeExecutionsLevelZero(t *testing.T) {
 			assert.Equal(t, map[string]interface{}{
 				"parent_id":                nil,
 				"parent_task_execution_id": nil,
 			}, filter)
 
-			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
+			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
 			return interfaces.NodeExecutionCollectionOutput{
 				NodeExecutions: []models.NodeExecution{
 					{
 						NodeExecutionKey: models.NodeExecutionKey{
 							NodeID: "node id",
@@ -856,14 +858,14 @@ func TestListNodeExecutionsLevelZero(t *testing.T) {
 		},
 		Limit: 1,
 		Token: "2",
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 	})
-	assert.Nil(t, err)
+	assert.NoError(t, err)
 	assert.Len(t, nodeExecutions.NodeExecutions, 1)
 	assert.True(t, proto.Equal(&admin.NodeExecution{
 		Id: &core.NodeExecutionIdentifier{
 			NodeId: "node id",
 			ExecutionId: &core.WorkflowExecutionIdentifier{
@@ -923,11 +925,11 @@ func TestListNodeExecutionsWithParent(t *testing.T) {
 			assert.Equal(t, common.NodeExecution, input.InlineFilters[3].GetEntity())
 			queryExpr, _ = input.InlineFilters[3].GetGormQueryExpr()
 			assert.Equal(t, parentID, queryExpr.Args)
 			assert.Equal(t, "parent_id = ?", queryExpr.Query)
 
-			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
+			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
 			return interfaces.NodeExecutionCollectionOutput{
 				NodeExecutions: []models.NodeExecution{
 					{
 						NodeExecutionKey: models.NodeExecutionKey{
 							NodeID: "node id",
@@ -956,11 +958,11 @@ func TestListNodeExecutionsWithParent(t *testing.T) {
 		},
 		Limit: 1,
 		Token: "2",
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 		UniqueParentId: "parent_1",
 	})
 	assert.Nil(t, err)
 	assert.Len(t, nodeExecutions.NodeExecutions, 1)
@@ -1073,24 +1075,26 @@ func TestListNodeExecutions_NothingToReturn(t *testing.T) {
 			interfaces.ExecutionCollectionOutput, error) {
 			listExecutionsCalled = true
 			return interfaces.ExecutionCollectionOutput{}, nil
 		})
 	nodeExecManager := NewNodeExecutionManager(repository, getMockExecutionsConfigProvider(), make([]string, 0), getMockStorageForExecTest(context.Background()), mockScope.NewTestScope(), mockNodeExecutionRemoteURL, nil, nil, &eventWriterMocks.NodeExecutionEventWriter{})
+
 	_, err := nodeExecManager.ListNodeExecutions(context.Background(), admin.NodeExecutionListRequest{
 		WorkflowExecutionId: &core.WorkflowExecutionIdentifier{
 			Project: "project",
 			Domain:  "domain",
 			Name:    "name",
 		},
 		Limit: 1,
 		Token: "2",
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 	})
-	assert.Nil(t, err)
+
+	assert.NoError(t, err)
 	assert.False(t, listExecutionsCalled)
 }
 
 func TestListNodeExecutionsForTask(t *testing.T) {
 	repository := repositoryMocks.NewMockRepository()
@@ -1137,11 +1141,11 @@ func TestListNodeExecutionsForTask(t *testing.T) {
 			assert.Equal(t, common.NodeExecution, input.InlineFilters[3].GetEntity())
 			queryExpr, _ = input.InlineFilters[3].GetGormQueryExpr()
 			assert.Equal(t, uint(8), queryExpr.Args)
 			assert.Equal(t, "parent_task_execution_id = ?", queryExpr.Query)
 
-			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
+			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
 			return interfaces.NodeExecutionCollectionOutput{
 				NodeExecutions: []models.NodeExecution{
 					{
 						NodeExecutionKey: models.NodeExecutionKey{
 							NodeID: "node id",
@@ -1182,11 +1186,11 @@ func TestListNodeExecutionsForTask(t *testing.T) {
 		},
 		Limit: 1,
 		Token: "2",
 		SortBy: &admin.Sort{
 			Direction: admin.Sort_ASCENDING,
-			Key:       "domain",
+			Key:       "execution_domain",
 		},
 	})
 	assert.Nil(t, err)
 	assert.Len(t, nodeExecutions.NodeExecutions, 1)
 	expectedMetadata := admin.NodeExecutionMetaData{
diff --git a/pkg/manager/impl/project_manager.go b/pkg/manager/impl/project_manager.go
index 27f4297..3c4b2d3 100644
--- a/pkg/manager/impl/project_manager.go
+++ b/pkg/manager/impl/project_manager.go
@@ -2,31 +2,33 @@ package impl
 
 import (
 	"context"
 	"strconv"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"google.golang.org/grpc/codes"
+
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"google.golang.org/grpc/codes"
 )
 
 type ProjectManager struct {
 	db     repoInterfaces.Repository
 	config runtimeInterfaces.Configuration
 }
 
-var alphabeticalSortParam, _ = common.NewSortParameter(admin.Sort{
+var alphabeticalSortParam, _ = common.NewSortParameter(&admin.Sort{
 	Direction: admin.Sort_ASCENDING,
 	Key:       "identifier",
-})
+}, models.ProjectColumns)
 
 func (m *ProjectManager) CreateProject(ctx context.Context, request admin.ProjectRegisterRequest) (
 	*admin.ProjectRegisterResponse, error) {
 	if err := validation.ValidateProjectRegisterRequest(request); err != nil {
 		return nil, err
@@ -59,17 +61,15 @@ func (m *ProjectManager) ListProjects(ctx context.Context, request admin.Project
 	filters, err := util.GetDbFilters(spec, common.Project)
 	if err != nil {
 		return nil, err
 	}
 
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
-	} else {
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.ProjectColumns)
+	if err != nil {
+		return nil, err
+	}
+	if sortParameter == nil {
 		sortParameter = alphabeticalSortParam
 	}
 
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
diff --git a/pkg/manager/impl/signal_manager.go b/pkg/manager/impl/signal_manager.go
index df2fbcc..ff7004f 100644
--- a/pkg/manager/impl/signal_manager.go
+++ b/pkg/manager/impl/signal_manager.go
@@ -2,28 +2,26 @@ package impl
 
 import (
 	"context"
 	"strconv"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/contextutils"
+	"github.com/flyteorg/flytestdlib/logger"
+	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/promutils/labeled"
+	"google.golang.org/grpc/codes"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
-
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
-	"github.com/flyteorg/flytestdlib/logger"
-	"github.com/flyteorg/flytestdlib/promutils"
-	"github.com/flyteorg/flytestdlib/promutils/labeled"
-
-	"google.golang.org/grpc/codes"
 )
 
 type signalMetrics struct {
 	Scope promutils.Scope
 	Set   labeled.Counter
@@ -81,16 +79,14 @@ func (s *SignalManager) ListSignals(ctx context.Context, request admin.SignalLis
 
 	filters, err := util.AddRequestFilters(request.Filters, common.Signal, identifierFilters)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.SignalColumns)
+	if err != nil {
+		return nil, err
 	}
 
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
diff --git a/pkg/manager/impl/task_execution_manager.go b/pkg/manager/impl/task_execution_manager.go
index 46967f2..ab0107f 100644
--- a/pkg/manager/impl/task_execution_manager.go
+++ b/pkg/manager/impl/task_execution_manager.go
@@ -3,38 +3,33 @@ package impl
 import (
 	"context"
 	"fmt"
 	"strconv"
 
-	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
-
-	"github.com/flyteorg/flytestdlib/promutils/labeled"
-
-	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
-	"github.com/golang/protobuf/proto"
-
-	"github.com/flyteorg/flytestdlib/storage"
-
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/contextutils"
-
+	"github.com/flyteorg/flytestdlib/logger"
 	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/promutils/labeled"
+	"github.com/flyteorg/flytestdlib/storage"
+	"github.com/golang/protobuf/proto"
 	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
+	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
+	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"github.com/flyteorg/flytestdlib/logger"
-	"google.golang.org/grpc/codes"
 )
 
 type taskExecutionMetrics struct {
 	Scope                      promutils.Scope
 	ActiveTaskExecutions       prometheus.Gauge
@@ -256,16 +251,14 @@ func (m *TaskExecutionManager) ListTaskExecutions(
 
 	filters, err := util.AddRequestFilters(request.Filters, common.TaskExecution, identifierFilters)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskExecutionColumns)
+	if err != nil {
+		return nil, err
 	}
 
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
diff --git a/pkg/manager/impl/task_manager.go b/pkg/manager/impl/task_manager.go
index b4346fc..ba02f5c 100644
--- a/pkg/manager/impl/task_manager.go
+++ b/pkg/manager/impl/task_manager.go
@@ -4,34 +4,31 @@ import (
 	"bytes"
 	"context"
 	"strconv"
 	"time"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/contextutils"
-
-	"github.com/prometheus/client_golang/prometheus"
-
+	"github.com/flyteorg/flytestdlib/logger"
 	"github.com/flyteorg/flytestdlib/promutils"
 	"github.com/flyteorg/flytestdlib/promutils/labeled"
-
 	"github.com/golang/protobuf/ptypes"
-
-	"github.com/flyteorg/flytestdlib/logger"
+	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
 	"github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
 	repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
 	workflowengine "github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"google.golang.org/grpc/codes"
 )
 
 type taskMetrics struct {
 	Scope            promutils.Scope
 	ClosureSizeBytes prometheus.Summary
@@ -167,17 +164,16 @@ func (t *TaskManager) ListTasks(ctx context.Context, request admin.ResourceListR
 
 	filters, err := util.GetDbFilters(spec, common.Task)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListTasks", request.Token)
 	}
@@ -224,17 +220,16 @@ func (t *TaskManager) ListUniqueTaskIdentifiers(ctx context.Context, request adm
 		Domain:  request.Domain,
 	}, common.Task)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListUniqueTaskIdentifiers", request.Token)
 	}
diff --git a/pkg/manager/impl/util/filters.go b/pkg/manager/impl/util/filters.go
index 70a65db..a085177 100644
--- a/pkg/manager/impl/util/filters.go
+++ b/pkg/manager/impl/util/filters.go
@@ -1,25 +1,25 @@
 // Util around parsing request filters
 package util
 
 import (
 	"context"
+	"fmt"
 	"regexp"
 	"strconv"
 	"strings"
 	"time"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/logger"
-
-	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"google.golang.org/grpc/codes"
-
-	"fmt"
+	"k8s.io/apimachinery/pkg/util/sets"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
+	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 )
 
 const (
 	filterExpressionSeperator = "+"
 	listValueSeparator        = ";"
@@ -118,10 +118,40 @@ func prepareValues(field string, values []string) (interface{}, error) {
 		return preparedValues[0], nil
 	}
 	return preparedValues, nil
 }
 
+var allowedJoinEntities = map[common.Entity]sets.String{
+	common.Execution:           sets.NewString(common.Execution, common.LaunchPlan, common.Workflow, common.Task, common.AdminTag),
+	common.LaunchPlan:          sets.NewString(common.LaunchPlan, common.Workflow),
+	common.NodeExecution:       sets.NewString(common.NodeExecution, common.Execution),
+	common.NodeExecutionEvent:  sets.NewString(common.NodeExecutionEvent),
+	common.Task:                sets.NewString(common.Task),
+	common.TaskExecution:       sets.NewString(common.TaskExecution, common.Task, common.Execution, common.NodeExecution),
+	common.Workflow:            sets.NewString(common.Workflow),
+	common.NamedEntity:         sets.NewString(common.NamedEntity),
+	common.NamedEntityMetadata: sets.NewString(common.NamedEntityMetadata),
+	common.Project:             sets.NewString(common.Project),
+	common.Signal:              sets.NewString(common.Signal),
+	common.AdminTag:            sets.NewString(common.AdminTag),
+}
+
+var entityColumns = map[common.Entity]sets.String{
+	common.Execution:           models.ExecutionColumns,
+	common.LaunchPlan:          models.LaunchPlanColumns,
+	common.NodeExecution:       models.NodeExecutionColumns,
+	common.NodeExecutionEvent:  models.NodeExecutionEventColumns,
+	common.Task:                models.TaskColumns,
+	common.TaskExecution:       models.TaskExecutionColumns,
+	common.Workflow:            models.WorkflowColumns,
+	common.NamedEntity:         models.NamedEntityColumns,
+	common.NamedEntityMetadata: models.NamedEntityMetadataColumns,
+	common.Project:             models.ProjectColumns,
+	common.Signal:              models.SignalColumns,
+	common.AdminTag:            models.AdminTagColumns,
+}
+
 func ParseFilters(filterParams string, primaryEntity common.Entity) ([]common.InlineFilter, error) {
 	// Multiple filters can be appended as URI-escaped strings joined by filterExpressionSeperator
 	filterExpressions := strings.Split(filterParams, filterExpressionSeperator)
 	parsedFilters := make([]common.InlineFilter, 0)
 	for _, filterExpression := range filterExpressions {
@@ -131,10 +161,23 @@ func ParseFilters(filterParams string, primaryEntity common.Entity) ([]common.In
 			// Poorly formatted filter string doesn't match expected regex.
 			return nil, shared.GetInvalidArgumentError(shared.Filters)
 		}
 		referencedEntity, field := parseField(matches[fieldMatchIndex], primaryEntity)
 
+		joinEntities, ok := allowedJoinEntities[primaryEntity]
+		if !ok {
+			return nil, fmt.Errorf("unsupported entity '%s'", primaryEntity)
+		}
+
+		if !joinEntities.Has(referencedEntity) {
+			return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "'%s' entity is not allowed in filters", referencedEntity)
+		}
+
+		if !entityColumns[referencedEntity].Has(field) {
+			return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "'%s.%s' is invalid filter", referencedEntity, field)
+		}
+
 		// Parse and transform values
 		parsedValues := parseRepeatedValues(matches[valueMatchIndex])
 		preparedValues, err := prepareValues(field, parsedValues)
 		if err != nil {
 			return nil, err
diff --git a/pkg/manager/impl/util/filters_test.go b/pkg/manager/impl/util/filters_test.go
index bf1f55e..6697885 100644
--- a/pkg/manager/impl/util/filters_test.go
+++ b/pkg/manager/impl/util/filters_test.go
@@ -4,15 +4,16 @@ import (
 	"context"
 	"testing"
 	"time"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"
-	"github.com/stretchr/testify/assert"
 )
 
 func TestParseRepeatedValues(t *testing.T) {
 	assert.EqualValues(t, []string{"foo", "bar"}, parseRepeatedValues("foo;bar"))
 }
@@ -62,55 +63,86 @@ func TestPrepareValues_RepeatedValues(t *testing.T) {
 	values, err = prepareValues("field", []string{"value a", "value b"})
 	assert.NoError(t, err)
 	assert.Equal(t, []interface{}{"value a", "value b"}, values)
 }
 
-func TestParseFilters(t *testing.T) {
-	filterExpression := "eq(foo, 123)+ne(version, TheWorst)+value_in(bar, 4;5;6)"
+func Test_ParseFilters_Success(t *testing.T) {
+	filterExpression := "eq(project, flytesnacks)+ne(domain, development)+value_in(type, 4;5;6)"
+
 	taskFilters, err := ParseFilters(filterExpression, common.Task)
+
 	assert.NoError(t, err)
+	require.Len(t, taskFilters, 3)
 
-	assert.Len(t, taskFilters, 3)
 	actualFilterExpression, _ := taskFilters[0].GetGormQueryExpr()
-	assert.Equal(t, "foo = ?", actualFilterExpression.Query)
-	assert.Equal(t, "123", actualFilterExpression.Args)
+	assert.Equal(t, "project = ?", actualFilterExpression.Query)
+	assert.Equal(t, "flytesnacks", actualFilterExpression.Args)
 
 	actualFilterExpression, _ = taskFilters[1].GetGormQueryExpr()
-	assert.Equal(t, "version <> ?", actualFilterExpression.Query)
-	assert.Equal(t, "TheWorst", actualFilterExpression.Args)
+	assert.Equal(t, "domain <> ?", actualFilterExpression.Query)
+	assert.Equal(t, "development", actualFilterExpression.Args)
 
 	actualFilterExpression, _ = taskFilters[2].GetGormQueryExpr()
-	assert.Equal(t, "bar in (?)", actualFilterExpression.Query)
+	assert.Equal(t, "type in (?)", actualFilterExpression.Query)
 	assert.Equal(t, []interface{}{"4", "5", "6"}, actualFilterExpression.Args)
+}
+
+func Test_ParseFilters_InvalidFunction(t *testing.T) {
+	filterExpression := "invalid_function(type,bar)"
+
+	_, err := ParseFilters(filterExpression, common.Task)
 
-	filterExpression = "invalid_function(foo,bar)"
-	_, err = ParseFilters(filterExpression, common.Task)
-	assert.Error(t, err)
 	assert.EqualError(t, err, "unrecognized filter function: invalid_function")
 }
 
+func Test_ParseFilters_UnsupportedEntity(t *testing.T) {
+	filterExpression := "eq(foo, 123)"
+
+	_, err := ParseFilters(filterExpression, "wrong")
+
+	assert.EqualError(t, err, "unsupported entity 'wrong'")
+}
+
+func Test_ParseFilters_InvalidJoinEntity(t *testing.T) {
+	filterExpression := "eq(project.name, 123)"
+
+	_, err := ParseFilters(filterExpression, common.Workflow)
+
+	assert.EqualError(t, err, "'p' entity is not allowed in filters")
+}
+
+func Test_ParseFilters_InvalidFilter(t *testing.T) {
+	filterExpression := "eq(foo, 123)"
+
+	_, err := ParseFilters(filterExpression, common.Task)
+
+	assert.EqualError(t, err, "'t.foo' is invalid filter")
+}
+
 func TestGetEqualityFilter(t *testing.T) {
 	filter, err := GetSingleValueEqualityFilter(common.Task, "field", "value")
 	assert.NoError(t, err)
 
 	actualFilterExpression, _ := filter.GetGormQueryExpr()
 	assert.Equal(t, "field = ?", actualFilterExpression.Query)
 	assert.Equal(t, "value", actualFilterExpression.Args)
 }
 
-func TestAddRequestFilters(t *testing.T) {
+func Test_AddRequestFilters(t *testing.T) {
 	filters, err := AddRequestFilters(
-		"ne(version, TheWorst)+eq(workflow.name, workflow)", common.Execution, make([]common.InlineFilter, 0))
-	assert.Nil(t, err)
-	assert.Len(t, filters, 2)
+		"ne(cluster, TheWorst)+eq(workflow.name, workflow)", common.Execution, make([]common.InlineFilter, 0))
+
+	assert.NoError(t, err)
+	require.Len(t, filters, 2)
+
 	expression, err := filters[0].GetGormQueryExpr()
-	assert.Nil(t, err)
-	assert.Equal(t, "version <> ?", expression.Query)
+	assert.NoError(t, err)
+	assert.Equal(t, "cluster <> ?", expression.Query)
 	assert.Equal(t, "TheWorst", expression.Args)
 
 	expression, err = filters[1].GetGormQueryExpr()
-	assert.Nil(t, err)
+	assert.NoError(t, err)
 	assert.Equal(t, testutils.NameQueryPattern, expression.Query)
 	assert.Equal(t, "workflow", expression.Args)
 }
 
 func TestGetDbFilters(t *testing.T) {
diff --git a/pkg/manager/impl/workflow_manager.go b/pkg/manager/impl/workflow_manager.go
index 09d6a0d..65996b5 100644
--- a/pkg/manager/impl/workflow_manager.go
+++ b/pkg/manager/impl/workflow_manager.go
@@ -4,11 +4,20 @@ import (
 	"bytes"
 	"context"
 	"strconv"
 	"time"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	compiler "github.com/flyteorg/flytepropeller/pkg/compiler/common"
 	"github.com/flyteorg/flytestdlib/contextutils"
+	"github.com/flyteorg/flytestdlib/logger"
+	"github.com/flyteorg/flytestdlib/promutils"
+	"github.com/flyteorg/flytestdlib/storage"
+	"github.com/golang/protobuf/ptypes"
+	"github.com/prometheus/client_golang/prometheus"
+	"google.golang.org/grpc/codes"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/util"
 	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"
@@ -17,19 +26,10 @@ import (
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
 	runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
 	workflowengine "github.com/flyteorg/flyteadmin/pkg/workflowengine/impl"
 	workflowengineInterfaces "github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	compiler "github.com/flyteorg/flytepropeller/pkg/compiler/common"
-	"github.com/flyteorg/flytestdlib/logger"
-	"github.com/flyteorg/flytestdlib/promutils"
-	"github.com/flyteorg/flytestdlib/storage"
-	"github.com/golang/protobuf/ptypes"
-	"github.com/prometheus/client_golang/prometheus"
-	"google.golang.org/grpc/codes"
 )
 
 var defaultStorageOptions = storage.Options{}
 
 type workflowMetrics struct {
@@ -250,17 +250,16 @@ func (w *WorkflowManager) ListWorkflows(
 		RequestFilters: request.Filters,
 	}, common.Workflow)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.WorkflowColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListWorkflows", request.Token)
 	}
@@ -304,17 +303,16 @@ func (w *WorkflowManager) ListWorkflowIdentifiers(ctx context.Context, request a
 		Domain:  request.Domain,
 	}, common.Workflow)
 	if err != nil {
 		return nil, err
 	}
-	var sortParameter common.SortParameter
-	if request.SortBy != nil {
-		sortParameter, err = common.NewSortParameter(*request.SortBy)
-		if err != nil {
-			return nil, err
-		}
+
+	sortParameter, err := common.NewSortParameter(request.SortBy, models.WorkflowColumns)
+	if err != nil {
+		return nil, err
 	}
+
 	offset, err := validation.ValidateToken(request.Token)
 	if err != nil {
 		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument,
 			"invalid pagination token %s for ListWorkflowIdentifiers", request.Token)
 	}
diff --git a/pkg/repositories/gormimpl/common.go b/pkg/repositories/gormimpl/common.go
index c022bd9..8011c11 100644
--- a/pkg/repositories/gormimpl/common.go
+++ b/pkg/repositories/gormimpl/common.go
@@ -1,17 +1,20 @@
 package gormimpl
 
 import (
 	"fmt"
+	"sync"
+
+	"google.golang.org/grpc/codes"
+	"gorm.io/gorm"
+	"gorm.io/gorm/schema"
+	"k8s.io/apimachinery/pkg/util/sets"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	adminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
-
-	"google.golang.org/grpc/codes"
-	"gorm.io/gorm"
 )
 
 const Project = "project"
 const Domain = "domain"
 const Name = "name"
@@ -113,5 +116,13 @@ func applyScopedFilters(tx *gorm.DB, inlineFilters []common.InlineFilter, mapFil
 	for _, mapFilter := range mapFilters {
 		tx = tx.Where(mapFilter.GetFilter())
 	}
 	return tx, nil
 }
+
+func modelColumns(v any) sets.String {
+	s, err := schema.Parse(v, &sync.Map{}, schema.NamingStrategy{})
+	if err != nil {
+		panic(err)
+	}
+	return sets.NewString(s.DBNames...)
+}
diff --git a/pkg/repositories/gormimpl/description_entity_repo.go b/pkg/repositories/gormimpl/description_entity_repo.go
index 1f5dceb..f698f90 100644
--- a/pkg/repositories/gormimpl/description_entity_repo.go
+++ b/pkg/repositories/gormimpl/description_entity_repo.go
@@ -1,18 +1,18 @@
 package gormimpl
 
 import (
 	"context"
 
-	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/promutils"
+	"gorm.io/gorm"
 
+	"github.com/flyteorg/flyteadmin/pkg/common"
 	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"gorm.io/gorm"
 )
 
 // DescriptionEntityRepo Implementation of DescriptionEntityRepoInterface.
 type DescriptionEntityRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/execution_repo.go b/pkg/repositories/gormimpl/execution_repo.go
index b128a28..a797992 100644
--- a/pkg/repositories/gormimpl/execution_repo.go
+++ b/pkg/repositories/gormimpl/execution_repo.go
@@ -3,16 +3,17 @@ package gormimpl
 import (
 	"context"
 	"errors"
 	"fmt"
 
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	"github.com/flyteorg/flytestdlib/promutils"
+
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	adminErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"github.com/flyteorg/flytestdlib/promutils"
 
 	"gorm.io/gorm"
 )
 
 // Implementation of ExecutionInterface.
diff --git a/pkg/repositories/gormimpl/execution_repo_test.go b/pkg/repositories/gormimpl/execution_repo_test.go
index 17cb857..a89c079 100644
--- a/pkg/repositories/gormimpl/execution_repo_test.go
+++ b/pkg/repositories/gormimpl/execution_repo_test.go
@@ -4,22 +4,21 @@ import (
 	"context"
 	"database/sql/driver"
 	"testing"
 	"time"
 
+	mocket "github.com/Selvatico/go-mocket"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
 	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-
-	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/stretchr/testify/assert"
 )
 
 var createdAt = time.Date(2018, time.February, 17, 00, 00, 00, 00, time.UTC).UTC()
 var executionStartedAt = time.Date(2018, time.February, 17, 00, 01, 00, 00, time.UTC).UTC()
 var executionUpdatedAt = time.Date(2018, time.February, 17, 00, 01, 00, 00, time.UTC).UTC()
@@ -248,46 +247,52 @@ func TestListExecutions_Order(t *testing.T) {
 	executionRepo := NewExecutionRepo(GetDbForTest(t), errors.NewTestErrorTransformer(), mockScope.NewTestScope())
 
 	executions := make([]map[string]interface{}, 0)
 	GlobalMock := mocket.Catcher.Reset()
 	// Only match on queries that include ordering by name
-	mockQuery := GlobalMock.NewMock().WithQuery(`name asc`)
+	mockQuery := GlobalMock.NewMock().WithQuery(`execution_name asc`)
 	mockQuery.WithReply(executions)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, err := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_ASCENDING,
-		Key:       "name",
-	})
-	_, err := executionRepo.List(context.Background(), interfaces.ListResourceInput{
+		Key:       "execution_name",
+	}, models.ExecutionColumns)
+	require.NoError(t, err)
+
+	_, err = executionRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.Task, "project", project),
 			getEqualityFilter(common.Task, "domain", domain),
 			getEqualityFilter(common.Task, "name", name),
 		},
 		Limit: 20,
 	})
+
 	assert.NoError(t, err)
 	assert.True(t, mockQuery.Triggered)
 }
 
 func TestListExecutions_WithTags(t *testing.T) {
 	executionRepo := NewExecutionRepo(GetDbForTest(t), errors.NewTestErrorTransformer(), mockScope.NewTestScope())
 
 	executions := make([]map[string]interface{}, 0)
 	GlobalMock := mocket.Catcher.Reset()
 	// Only match on queries that include ordering by name
-	mockQuery := GlobalMock.NewMock().WithQuery(`name asc`)
+	mockQuery := GlobalMock.NewMock().WithQuery(`execution_name asc`)
 	mockQuery.WithReply(executions)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, err := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_ASCENDING,
-		Key:       "name",
-	})
+		Key:       "execution_name",
+	}, models.ExecutionColumns)
+	require.NoError(t, err)
+
 	vals := []string{"tag1", "tag2"}
 	tagFilter, err := common.NewRepeatedValueFilter(common.ExecutionAdminTag, common.ValueIn, "admin_tag_name", vals)
 	assert.NoError(t, err)
+
 	_, err = executionRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.Task, "project", project),
 			getEqualityFilter(common.Task, "domain", domain),
diff --git a/pkg/repositories/gormimpl/launch_plan_repo.go b/pkg/repositories/gormimpl/launch_plan_repo.go
index dc379ed..d72eb6f 100644
--- a/pkg/repositories/gormimpl/launch_plan_repo.go
+++ b/pkg/repositories/gormimpl/launch_plan_repo.go
@@ -6,15 +6,16 @@ import (
 	"time"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/promutils"
 
+	"github.com/flyteorg/flytestdlib/logger"
+	"gorm.io/gorm"
+
 	adminErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flytestdlib/logger"
-	"gorm.io/gorm"
 )
 
 const launchPlanTableName = "launch_plans"
 
 type launchPlanMetrics struct {
diff --git a/pkg/repositories/gormimpl/launch_plan_repo_test.go b/pkg/repositories/gormimpl/launch_plan_repo_test.go
index f96bd79..39d557d 100644
--- a/pkg/repositories/gormimpl/launch_plan_repo_test.go
+++ b/pkg/repositories/gormimpl/launch_plan_repo_test.go
@@ -3,19 +3,19 @@ package gormimpl
 import (
 	"context"
 	"database/sql/driver"
 	"testing"
 
+	mocket "github.com/Selvatico/go-mocket"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
 
-	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	"github.com/stretchr/testify/assert"
 )
 
 const workflowID = uint(1)
 
 var launchPlanSpec = []byte{1, 2}
@@ -343,14 +343,14 @@ func TestListLaunchPlans_Order(t *testing.T) {
 	// Only match on queries that include ordering by project
 	mockQuery := GlobalMock.NewMock()
 	mockQuery.WithQuery(`project desc`)
 	mockQuery.WithReply(launchPlans)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, _ := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
 		Key:       "project",
-	})
+	}, models.LaunchPlanColumns)
 	_, err := launchPlanRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.LaunchPlan, "project", project),
 			getEqualityFilter(common.LaunchPlan, "domain", domain),
diff --git a/pkg/repositories/gormimpl/named_entity_repo.go b/pkg/repositories/gormimpl/named_entity_repo.go
index 8e02390..66a9f81 100644
--- a/pkg/repositories/gormimpl/named_entity_repo.go
+++ b/pkg/repositories/gormimpl/named_entity_repo.go
@@ -3,19 +3,19 @@ package gormimpl
 import (
 	"context"
 	"fmt"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	"github.com/flyteorg/flytestdlib/promutils"
 	"google.golang.org/grpc/codes"
+	"gorm.io/gorm"
 
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	adminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flytestdlib/promutils"
-	"gorm.io/gorm"
 )
 
 const innerJoinTableAlias = "entities"
 
 var resourceTypeToTableName = map[core.ResourceType]string{
diff --git a/pkg/repositories/gormimpl/named_entity_repo_test.go b/pkg/repositories/gormimpl/named_entity_repo_test.go
index d586a2c..39fb861 100644
--- a/pkg/repositories/gormimpl/named_entity_repo_test.go
+++ b/pkg/repositories/gormimpl/named_entity_repo_test.go
@@ -7,15 +7,16 @@ import (
 	"github.com/flyteorg/flyteadmin/pkg/common"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 
 	mocket "github.com/Selvatico/go-mocket"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-	"github.com/stretchr/testify/assert"
 )
 
 func getMockNamedEntityResponseFromDb(expected models.NamedEntity) map[string]interface{} {
 	metadata := make(map[string]interface{})
 	metadata["resource_type"] = expected.ResourceType
@@ -155,14 +156,14 @@ func TestListNamedEntity(t *testing.T) {
 	mockQuery := GlobalMock.NewMock()
 
 	mockQuery.WithQuery(
 		`SELECT entities.project,entities.domain,entities.name,'2' AS resource_type,named_entity_metadata.description,named_entity_metadata.state FROM "named_entity_metadata" RIGHT JOIN (SELECT project,domain,name FROM "workflows" WHERE "domain" = $1 AND "project" = $2 GROUP BY project, domain, name ORDER BY name desc LIMIT 20) AS entities ON named_entity_metadata.resource_type = 2 AND named_entity_metadata.project = entities.project AND named_entity_metadata.domain = entities.domain AND named_entity_metadata.name = entities.name GROUP BY entities.project, entities.domain, entities.name, named_entity_metadata.description, named_entity_metadata.state ORDER BY name desc`).WithReply(results)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, _ := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
 		Key:       "name",
-	})
+	}, models.NamedEntityColumns)
 	output, err := metadataRepo.List(context.Background(), interfaces.ListNamedEntityInput{
 		ResourceType: resourceType,
 		Project:      "admintests",
 		Domain:       "development",
 		ListResourceInput: interfaces.ListResourceInput{
diff --git a/pkg/repositories/gormimpl/node_execution_event_repo.go b/pkg/repositories/gormimpl/node_execution_event_repo.go
index 8c8b3f9..cedf824 100644
--- a/pkg/repositories/gormimpl/node_execution_event_repo.go
+++ b/pkg/repositories/gormimpl/node_execution_event_repo.go
@@ -1,15 +1,16 @@
 package gormimpl
 
 import (
 	"context"
 
+	"github.com/flyteorg/flytestdlib/promutils"
+	"gorm.io/gorm"
+
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flytestdlib/promutils"
-	"gorm.io/gorm"
 )
 
 type NodeExecutionEventRepo struct {
 	db               *gorm.DB
 	errorTransformer errors.ErrorTransformer
diff --git a/pkg/repositories/gormimpl/node_execution_repo.go b/pkg/repositories/gormimpl/node_execution_repo.go
index 65cd8a7..71b6de4 100644
--- a/pkg/repositories/gormimpl/node_execution_repo.go
+++ b/pkg/repositories/gormimpl/node_execution_repo.go
@@ -4,17 +4,16 @@ import (
 	"context"
 	"errors"
 	"fmt"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
 	"github.com/flyteorg/flytestdlib/promutils"
+	"gorm.io/gorm"
 
 	adminErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"gorm.io/gorm"
 )
 
 // Implementation of NodeExecutionInterface.
 type NodeExecutionRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/node_execution_repo_test.go b/pkg/repositories/gormimpl/node_execution_repo_test.go
index d3f778f..b646a1d 100644
--- a/pkg/repositories/gormimpl/node_execution_repo_test.go
+++ b/pkg/repositories/gormimpl/node_execution_repo_test.go
@@ -3,25 +3,24 @@ package gormimpl
 import (
 	"context"
 	"testing"
 	"time"
 
-	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
-	"google.golang.org/grpc/codes"
-	"gorm.io/gorm"
-
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-
+	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"google.golang.org/grpc/codes"
+	"gorm.io/gorm"
 
-	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteadmin/pkg/common"
+	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/stretchr/testify/assert"
 )
 
 var nodePhase = core.NodeExecution_RUNNING.String()
 
 var nodeStartedAt = time.Date(2018, time.February, 17, 00, 00, 00, 00, time.UTC)
@@ -246,24 +245,27 @@ func TestListNodeExecutions_Order(t *testing.T) {
 	nodeExecutions := make([]map[string]interface{}, 0)
 
 	GlobalMock := mocket.Catcher.Reset()
 	// Only match on queries that include ordering by project
 	mockQuery := GlobalMock.NewMock()
-	mockQuery.WithQuery(`project desc`)
+	mockQuery.WithQuery(`execution_project desc`)
 	mockQuery.WithReply(nodeExecutions)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, err := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
-		Key:       "project",
-	})
-	_, err := nodeExecutionRepo.List(context.Background(), interfaces.ListResourceInput{
+		Key:       "execution_project",
+	}, models.NodeExecutionColumns)
+	require.NoError(t, err)
+
+	_, err = nodeExecutionRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.NodeExecution, "phase", nodePhase),
 		},
 		Limit: 20,
 	})
+
 	assert.NoError(t, err)
 	assert.True(t, mockQuery.Triggered)
 }
 
 func TestListNodeExecutions_MissingParameters(t *testing.T) {
diff --git a/pkg/repositories/gormimpl/project_repo.go b/pkg/repositories/gormimpl/project_repo.go
index 7541fce..c9ee444 100644
--- a/pkg/repositories/gormimpl/project_repo.go
+++ b/pkg/repositories/gormimpl/project_repo.go
@@ -2,18 +2,16 @@ package gormimpl
 
 import (
 	"context"
 	"errors"
 
-	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
-	"google.golang.org/grpc/codes"
-
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 	"github.com/flyteorg/flytestdlib/promutils"
-
+	"google.golang.org/grpc/codes"
 	"gorm.io/gorm"
 
+	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
 	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 )
 
diff --git a/pkg/repositories/gormimpl/project_repo_test.go b/pkg/repositories/gormimpl/project_repo_test.go
index 1450721..019cd22 100644
--- a/pkg/repositories/gormimpl/project_repo_test.go
+++ b/pkg/repositories/gormimpl/project_repo_test.go
@@ -3,23 +3,24 @@ package gormimpl
 import (
 	"context"
 	"testing"
 
 	mocket "github.com/Selvatico/go-mocket"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-	"github.com/stretchr/testify/assert"
 )
 
-var alphabeticalSortParam, _ = common.NewSortParameter(admin.Sort{
+var alphabeticalSortParam, _ = common.NewSortParameter(&admin.Sort{
 	Direction: admin.Sort_ASCENDING,
 	Key:       "identifier",
-})
+}, models.ProjectColumns)
 
 func TestCreateProject(t *testing.T) {
 	projectRepo := NewProjectRepo(GetDbForTest(t), errors.NewTestErrorTransformer(), mockScope.NewTestScope())
 	GlobalMock := mocket.Catcher.Reset()
 
@@ -92,11 +93,12 @@ func testListProjects(input interfaces.ListResourceInput, sql string, t *testing
 	assert.Equal(t, int32(admin.Project_ACTIVE), *output[0].State)
 }
 
 func TestListProjects(t *testing.T) {
 	filter, err := common.NewSingleValueFilter(common.Project, common.Equal, "name", "foo")
-	assert.Nil(t, err)
+
+	assert.NoError(t, err)
 	testListProjects(interfaces.ListResourceInput{
 		Offset:        0,
 		Limit:         1,
 		InlineFilters: []common.InlineFilter{filter},
 		SortParameter: alphabeticalSortParam,
diff --git a/pkg/repositories/gormimpl/resource_repo_test.go b/pkg/repositories/gormimpl/resource_repo_test.go
index 1ea145d..375eb74 100644
--- a/pkg/repositories/gormimpl/resource_repo_test.go
+++ b/pkg/repositories/gormimpl/resource_repo_test.go
@@ -2,19 +2,18 @@ package gormimpl
 
 import (
 	"context"
 	"testing"
 
+	mocket "github.com/Selvatico/go-mocket"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
 	"gorm.io/gorm"
 
-	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
-
-	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-	"github.com/stretchr/testify/assert"
 )
 
 const resourceTestWorkflowName = "workflow"
 const resourceTypeStr = "resource-type"
 
diff --git a/pkg/repositories/gormimpl/signal_repo.go b/pkg/repositories/gormimpl/signal_repo.go
index b87f703..d1dec1b 100644
--- a/pkg/repositories/gormimpl/signal_repo.go
+++ b/pkg/repositories/gormimpl/signal_repo.go
@@ -2,20 +2,18 @@ package gormimpl
 
 import (
 	"context"
 	"errors"
 
+	"github.com/flyteorg/flytestdlib/promutils"
+	"google.golang.org/grpc/codes"
+	"gorm.io/gorm"
+
 	adminerrors "github.com/flyteorg/flyteadmin/pkg/errors"
 	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-
-	"github.com/flyteorg/flytestdlib/promutils"
-
-	"google.golang.org/grpc/codes"
-
-	"gorm.io/gorm"
 )
 
 // SignalRepo is an implementation of SignalRepoInterface.
 type SignalRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/task_execution_repo.go b/pkg/repositories/gormimpl/task_execution_repo.go
index b864d80..8f3fd5e 100644
--- a/pkg/repositories/gormimpl/task_execution_repo.go
+++ b/pkg/repositories/gormimpl/task_execution_repo.go
@@ -3,17 +3,16 @@ package gormimpl
 import (
 	"context"
 	"errors"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
 	"github.com/flyteorg/flytestdlib/promutils"
+	"gorm.io/gorm"
 
 	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"gorm.io/gorm"
 )
 
 // Implementation of TaskExecutionInterface.
 type TaskExecutionRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/task_execution_repo_test.go b/pkg/repositories/gormimpl/task_execution_repo_test.go
index 9556453..64a79ae 100644
--- a/pkg/repositories/gormimpl/task_execution_repo_test.go
+++ b/pkg/repositories/gormimpl/task_execution_repo_test.go
@@ -3,19 +3,19 @@ package gormimpl
 import (
 	"context"
 	"testing"
 	"time"
 
+	mocket "github.com/Selvatico/go-mocket"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
 
-	mocket "github.com/Selvatico/go-mocket"
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-	"github.com/stretchr/testify/assert"
 )
 
 var taskPhase = core.TaskExecution_ABORTED.String()
 
 var taskCreatedAt = time.Date(2018, time.January, 1, 00, 00, 00, 00, time.UTC)
diff --git a/pkg/repositories/gormimpl/task_repo.go b/pkg/repositories/gormimpl/task_repo.go
index fae18c0..03e6907 100644
--- a/pkg/repositories/gormimpl/task_repo.go
+++ b/pkg/repositories/gormimpl/task_repo.go
@@ -3,17 +3,16 @@ package gormimpl
 import (
 	"context"
 	"errors"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
-
 	"github.com/flyteorg/flytestdlib/promutils"
+	"gorm.io/gorm"
 
 	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"gorm.io/gorm"
 )
 
 // Implementation of TaskRepoInterface.
 type TaskRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/task_repo_test.go b/pkg/repositories/gormimpl/task_repo_test.go
index 678a5c3..98fbdc0 100644
--- a/pkg/repositories/gormimpl/task_repo_test.go
+++ b/pkg/repositories/gormimpl/task_repo_test.go
@@ -7,15 +7,16 @@ import (
 	mockScope "github.com/flyteorg/flytestdlib/promutils"
 
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
 
 	mocket "github.com/Selvatico/go-mocket"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/stretchr/testify/assert"
 )
 
 const pythonTestTaskType = "python-task"
 
 func TestCreateTask(t *testing.T) {
@@ -195,14 +196,14 @@ func TestListTasks_Order(t *testing.T) {
 	// Only match on queries that include ordering by project
 	mockQuery := GlobalMock.NewMock()
 	mockQuery.WithQuery(`project desc`)
 	mockQuery.WithReply(tasks)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, _ := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
 		Key:       "project",
-	})
+	}, models.TaskColumns)
 	_, err := taskRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.Task, "project", project),
 			getEqualityFilter(common.Task, "domain", domain),
diff --git a/pkg/repositories/gormimpl/workflow_repo.go b/pkg/repositories/gormimpl/workflow_repo.go
index 69b711d..8ade1e9 100644
--- a/pkg/repositories/gormimpl/workflow_repo.go
+++ b/pkg/repositories/gormimpl/workflow_repo.go
@@ -2,16 +2,17 @@ package gormimpl
 
 import (
 	"context"
 	"errors"
 
-	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
-	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
-	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
 	"github.com/flyteorg/flytestdlib/promutils"
 	"gorm.io/gorm"
+
+	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
+	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
 )
 
 // Implementation of WorkflowRepoInterface.
 type WorkflowRepo struct {
 	db               *gorm.DB
diff --git a/pkg/repositories/gormimpl/workflow_repo_test.go b/pkg/repositories/gormimpl/workflow_repo_test.go
index ee300d6..7e173b9 100644
--- a/pkg/repositories/gormimpl/workflow_repo_test.go
+++ b/pkg/repositories/gormimpl/workflow_repo_test.go
@@ -3,17 +3,18 @@ package gormimpl
 import (
 	"context"
 	"testing"
 
 	mocket "github.com/Selvatico/go-mocket"
+	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
+	mockScope "github.com/flyteorg/flytestdlib/promutils"
+	"github.com/stretchr/testify/assert"
+
 	"github.com/flyteorg/flyteadmin/pkg/common"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/errors"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
 	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
-	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
-	mockScope "github.com/flyteorg/flytestdlib/promutils"
-	"github.com/stretchr/testify/assert"
 )
 
 var typedInterface = []byte{1, 2, 3}
 
 const remoteSpecIdentifier = "remote spec id"
@@ -180,14 +181,14 @@ func TestListWorkflows_Order(t *testing.T) {
 	// Only match on queries that include ordering by project
 	mockQuery := GlobalMock.NewMock()
 	mockQuery.WithQuery(`project desc`)
 	mockQuery.WithReply(workflows)
 
-	sortParameter, _ := common.NewSortParameter(admin.Sort{
+	sortParameter, _ := common.NewSortParameter(&admin.Sort{
 		Direction: admin.Sort_DESCENDING,
 		Key:       "project",
-	})
+	}, models.WorkflowColumns)
 	_, err := workflowRepo.List(context.Background(), interfaces.ListResourceInput{
 		SortParameter: sortParameter,
 		InlineFilters: []common.InlineFilter{
 			getEqualityFilter(common.Workflow, "project", project),
 			getEqualityFilter(common.Workflow, "domain", domain),
diff --git a/pkg/repositories/models/base_model.go b/pkg/repositories/models/base_model.go
index bfc5776..1980289 100644
--- a/pkg/repositories/models/base_model.go
+++ b/pkg/repositories/models/base_model.go
@@ -1,13 +1,27 @@
 package models
 
-import "time"
+import (
+	"sync"
+	"time"
+
+	"gorm.io/gorm/schema"
+	"k8s.io/apimachinery/pkg/util/sets"
+)
 
 // This is the base model definition every flyteadmin model embeds.
 // This is nearly identical to http://doc.gorm.io/models.html#conventions except that flyteadmin models define their
 // own primary keys rather than use the ID as the primary key
 type BaseModel struct {
 	ID        uint `gorm:"index;autoIncrement"`
 	CreatedAt time.Time
 	UpdatedAt time.Time
 	DeletedAt *time.Time `gorm:"index"`
 }
+
+func modelColumns(v any) sets.String {
+	s, err := schema.Parse(v, &sync.Map{}, schema.NamingStrategy{})
+	if err != nil {
+		panic(err)
+	}
+	return sets.NewString(s.DBNames...)
+}
diff --git a/pkg/repositories/models/description_entity.go b/pkg/repositories/models/description_entity.go
index 3a5c716..1483128 100644
--- a/pkg/repositories/models/description_entity.go
+++ b/pkg/repositories/models/description_entity.go
@@ -26,5 +26,7 @@ type DescriptionEntity struct {
 
 	LongDescription []byte
 
 	SourceCode
 }
+
+var DescriptionEntityColumns = modelColumns(DescriptionEntity{})
diff --git a/pkg/repositories/models/execution.go b/pkg/repositories/models/execution.go
index 931a3b7..87e2c6c 100644
--- a/pkg/repositories/models/execution.go
+++ b/pkg/repositories/models/execution.go
@@ -78,5 +78,10 @@ func (b *AdminTag) BeforeCreate(tx *gorm.DB) (err error) {
 		Columns:   []clause.Column{{Name: "name"}},            // key column
 		DoUpdates: clause.AssignmentColumns([]string{"name"}), // column needed to be updated
 	})
 	return nil
 }
+
+var (
+	ExecutionColumns = modelColumns(Execution{})
+	AdminTagColumns  = modelColumns(AdminTag{})
+)
diff --git a/pkg/repositories/models/launch_plan.go b/pkg/repositories/models/launch_plan.go
index 2b27875..1a12dd2 100644
--- a/pkg/repositories/models/launch_plan.go
+++ b/pkg/repositories/models/launch_plan.go
@@ -30,5 +30,7 @@ type LaunchPlan struct {
 	State *int32 `gorm:"default:0"`
 	// Hash of the launch plan
 	Digest       []byte
 	ScheduleType LaunchPlanScheduleType
 }
+
+var LaunchPlanColumns = modelColumns(LaunchPlan{})
diff --git a/pkg/repositories/models/named_entity.go b/pkg/repositories/models/named_entity.go
index 966676d..ef5d75a 100644
--- a/pkg/repositories/models/named_entity.go
+++ b/pkg/repositories/models/named_entity.go
@@ -38,5 +38,10 @@ type NamedEntityKey struct {
 // Composes an identifier (NamedEntity) and its associated metadata fields
 type NamedEntity struct {
 	NamedEntityKey
 	NamedEntityMetadataFields
 }
+
+var (
+	NamedEntityColumns         = modelColumns(NamedEntity{})
+	NamedEntityMetadataColumns = modelColumns(NamedEntityMetadata{})
+)
diff --git a/pkg/repositories/models/node_execution.go b/pkg/repositories/models/node_execution.go
index 100ab55..114a102 100644
--- a/pkg/repositories/models/node_execution.go
+++ b/pkg/repositories/models/node_execution.go
@@ -49,5 +49,7 @@ type NodeExecution struct {
 	// In the case of dynamic workflow nodes, the remote closure is uploaded to the path specified here.
 	DynamicWorkflowRemoteClosureReference string
 	// Metadata that is only relevant to the flyteadmin service that is used to parse the model and track additional attributes.
 	InternalData []byte
 }
+
+var NodeExecutionColumns = modelColumns(NodeExecution{})
diff --git a/pkg/repositories/models/node_execution_event.go b/pkg/repositories/models/node_execution_event.go
index cd362c8..534c84d 100644
--- a/pkg/repositories/models/node_execution_event.go
+++ b/pkg/repositories/models/node_execution_event.go
@@ -9,5 +9,7 @@ type NodeExecutionEvent struct {
 	NodeExecutionKey
 	RequestID  string
 	OccurredAt time.Time
 	Phase      string `gorm:"primary_key"`
 }
+
+var NodeExecutionEventColumns = modelColumns(NodeExecutionEvent{})
diff --git a/pkg/repositories/models/project.go b/pkg/repositories/models/project.go
index a5feedb..d22befc 100644
--- a/pkg/repositories/models/project.go
+++ b/pkg/repositories/models/project.go
@@ -7,5 +7,7 @@ type Project struct {
 	Description string `gorm:"type:varchar(300)"`
 	Labels      []byte
 	// GORM doesn't save the zero value for ints, so we use a pointer for the State field
 	State *int32 `gorm:"default:0;index"`
 }
+
+var ProjectColumns = modelColumns(Project{})
diff --git a/pkg/repositories/models/signal.go b/pkg/repositories/models/signal.go
index 8a7fac6..3ae90ee 100644
--- a/pkg/repositories/models/signal.go
+++ b/pkg/repositories/models/signal.go
@@ -11,5 +11,7 @@ type Signal struct {
 	BaseModel
 	SignalKey
 	Type  []byte `gorm:"not null"`
 	Value []byte
 }
+
+var SignalColumns = modelColumns(Signal{})
diff --git a/pkg/repositories/models/task.go b/pkg/repositories/models/task.go
index 53ee1c8..ea798ed 100644
--- a/pkg/repositories/models/task.go
+++ b/pkg/repositories/models/task.go
@@ -21,5 +21,7 @@ type Task struct {
 	// Task type (also stored in the closure put promoted as a column for filtering).
 	Type string `valid:"length(0|255)"`
 	// ShortDescription for the task.
 	ShortDescription string
 }
+
+var TaskColumns = modelColumns(Task{})
diff --git a/pkg/repositories/models/task_execution.go b/pkg/repositories/models/task_execution.go
index d1f8ad2..27e20b5 100644
--- a/pkg/repositories/models/task_execution.go
+++ b/pkg/repositories/models/task_execution.go
@@ -35,5 +35,7 @@ type TaskExecution struct {
 	TaskExecutionUpdatedAt *time.Time
 	Duration               time.Duration
 	// The child node executions (if any) launched by this task execution.
 	ChildNodeExecution []NodeExecution `gorm:"foreignkey:ParentTaskExecutionID;references:ID"`
 }
+
+var TaskExecutionColumns = modelColumns(TaskExecution{})
diff --git a/pkg/repositories/models/workflow.go b/pkg/repositories/models/workflow.go
index f431c47..e527ea4 100644
--- a/pkg/repositories/models/workflow.go
+++ b/pkg/repositories/models/workflow.go
@@ -17,5 +17,7 @@ type Workflow struct {
 	// Hash of the compiled workflow closure
 	Digest []byte
 	// ShortDescription for the workflow.
 	ShortDescription string
 }
+
+var WorkflowColumns = modelColumns(Workflow{})

Vulnerable code: 	"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/common"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"

var descCreatedAtSortParam = admin.Sort{
	Direction: admin.Sort_DESCENDING,
	Key:       "created_at",
}

var descCreatedAtSortDBParam, _ = common.NewSortParameter(descCreatedAtSortParam)
func NewSortParameter(sort admin.Sort) (SortParameter, error) {
		gormOrderExpression = fmt.Sprintf(gormDescending, sort.Key)
		gormOrderExpression = fmt.Sprintf(gormAscending, sort.Key)
	sortParameter, err := NewSortParameter(admin.Sort{
	})
	assert.Nil(t, err)
	sortParameter, err := NewSortParameter(admin.Sort{
	})
	assert.Nil(t, err)

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flytestdlib/contextutils"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	"github.com/flyteorg/flytestdlib/promutils/labeled"

	"github.com/flyteorg/flyteadmin/plugins"


	"github.com/flyteorg/flyteadmin/auth"

	"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"

	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/common"

	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/storage"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"google.golang.org/grpc/codes"

	"github.com/benbjohnson/clock"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	"github.com/golang/protobuf/proto"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}

	"github.com/flyteorg/flyteadmin/plugins"

	"google.golang.org/grpc/status"

	"google.golang.org/protobuf/types/known/timestamppb"
	"github.com/flyteorg/flyteadmin/pkg/common"
	commonTestUtils "github.com/flyteorg/flyteadmin/pkg/common/testutils"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/executions"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	managerInterfaces "github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
	managerMocks "github.com/flyteorg/flyteadmin/pkg/manager/mocks"
	"github.com/flyteorg/flyteadmin/pkg/runtime"


	eventWriterMocks "github.com/flyteorg/flyteadmin/pkg/async/events/mocks"

	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"

	"github.com/flyteorg/flytestdlib/storage"

	"time"

	"fmt"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/ptypes/wrappers"
	"github.com/stretchr/testify/assert"
		assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "domain",
		assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "domain",


	"github.com/flyteorg/flytestdlib/logger"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}

	"google.golang.org/grpc/codes"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"

	"github.com/flyteorg/flytestdlib/promutils/labeled"

	eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/interfaces"

	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
	"github.com/golang/protobuf/proto"

	"github.com/flyteorg/flytestdlib/storage"


	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	"github.com/flyteorg/flytestdlib/logger"

	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"

	"fmt"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if sortBy != nil {
		sortParameter, err = common.NewSortParameter(*sortBy)
		if err != nil {
			return nil, err
		}
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"
	"github.com/flyteorg/flyteadmin/pkg/common"
	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
	dataMocks "github.com/flyteorg/flyteadmin/pkg/data/mocks"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
	repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "domain",
	assert.Nil(t, err)
			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "domain",
			Key:       "domain",
	assert.Nil(t, err)
			assert.Equal(t, "domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "domain",
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"google.golang.org/grpc/codes"
var alphabeticalSortParam, _ = common.NewSortParameter(admin.Sort{
})
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	} else {

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"

	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"github.com/flyteorg/flytestdlib/promutils/labeled"

	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"

	"github.com/flyteorg/flytestdlib/promutils/labeled"

	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
	"github.com/golang/protobuf/proto"

	"github.com/flyteorg/flytestdlib/storage"


	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}

	"github.com/prometheus/client_golang/prometheus"



	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}

	"github.com/flyteorg/flyteadmin/pkg/errors"

	"fmt"
	"github.com/stretchr/testify/assert"
func TestParseFilters(t *testing.T) {
	filterExpression := "eq(foo, 123)+ne(version, TheWorst)+value_in(bar, 4;5;6)"
	assert.Len(t, taskFilters, 3)
	assert.Equal(t, "foo = ?", actualFilterExpression.Query)
	assert.Equal(t, "123", actualFilterExpression.Args)
	assert.Equal(t, "version <> ?", actualFilterExpression.Query)
	assert.Equal(t, "TheWorst", actualFilterExpression.Args)
	assert.Equal(t, "bar in (?)", actualFilterExpression.Query)
	filterExpression = "invalid_function(foo,bar)"
	_, err = ParseFilters(filterExpression, common.Task)
	assert.Error(t, err)
func TestAddRequestFilters(t *testing.T) {
		"ne(version, TheWorst)+eq(workflow.name, workflow)", common.Execution, make([]common.InlineFilter, 0))
	assert.Nil(t, err)
	assert.Len(t, filters, 2)
	assert.Nil(t, err)
	assert.Equal(t, "version <> ?", expression.Query)
	assert.Nil(t, err)
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	compiler "github.com/flyteorg/flytepropeller/pkg/compiler/common"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/ptypes"
	"github.com/prometheus/client_golang/prometheus"
	"google.golang.org/grpc/codes"
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}
	var sortParameter common.SortParameter
	if request.SortBy != nil {
		sortParameter, err = common.NewSortParameter(*request.SortBy)
		if err != nil {
			return nil, err
		}

	"google.golang.org/grpc/codes"
	"gorm.io/gorm"
	"github.com/flyteorg/flyteadmin/pkg/common"
	"gorm.io/gorm"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/promutils"

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"

	mocket "github.com/Selvatico/go-mocket"
	"github.com/stretchr/testify/assert"
	mockQuery := GlobalMock.NewMock().WithQuery(`name asc`)
	sortParameter, _ := common.NewSortParameter(admin.Sort{
		Key:       "name",
	})
	_, err := executionRepo.List(context.Background(), interfaces.ListResourceInput{
	mockQuery := GlobalMock.NewMock().WithQuery(`name asc`)
	sortParameter, _ := common.NewSortParameter(admin.Sort{
		Key:       "name",
	})
	"github.com/flyteorg/flytestdlib/logger"
	"gorm.io/gorm"
	mocket "github.com/Selvatico/go-mocket"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/stretchr/testify/assert"
	sortParameter, _ := common.NewSortParameter(admin.Sort{
	})
	"github.com/flyteorg/flytestdlib/promutils"
	"gorm.io/gorm"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"
	sortParameter, _ := common.NewSortParameter(admin.Sort{
	})
	"github.com/flyteorg/flytestdlib/promutils"
	"gorm.io/gorm"

	"gorm.io/gorm"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"google.golang.org/grpc/codes"
	"gorm.io/gorm"

	mockScope "github.com/flyteorg/flytestdlib/promutils"

	mocket "github.com/Selvatico/go-mocket"
	"github.com/stretchr/testify/assert"
	mockQuery.WithQuery(`project desc`)
	sortParameter, _ := common.NewSortParameter(admin.Sort{
		Key:       "project",
	})
	_, err := nodeExecutionRepo.List(context.Background(), interfaces.ListResourceInput{
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"google.golang.org/grpc/codes"


	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"
var alphabeticalSortParam, _ = common.NewSortParameter(admin.Sort{
})
	assert.Nil(t, err)
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"

	mocket "github.com/Selvatico/go-mocket"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"

	"github.com/flyteorg/flytestdlib/promutils"

	"google.golang.org/grpc/codes"

	"gorm.io/gorm"

	"gorm.io/gorm"
	mocket "github.com/Selvatico/go-mocket"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/stretchr/testify/assert"

	"gorm.io/gorm"
	"github.com/stretchr/testify/assert"
	sortParameter, _ := common.NewSortParameter(admin.Sort{
	})
	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"
	sortParameter, _ := common.NewSortParameter(admin.Sort{
	})
import "time"
Fixed code: 
	"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/common"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
var descCreatedAtSortParam = admin.Sort{
	Direction: admin.Sort_DESCENDING,
	Key:       "created_at",
}

var descCreatedAtSortDBParam, _ = common.NewSortParameter(&descCreatedAtSortParam, models.ProjectColumns)

	"k8s.io/apimachinery/pkg/util/sets"
func NewSortParameter(sort *admin.Sort, allowed sets.String) (SortParameter, error) {
	if sort == nil {
		return nil, nil
	}

	key := sort.Key
	if !allowed.Has(key) {
		return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "invalid sort key '%s'", key)
	}

		gormOrderExpression = fmt.Sprintf(gormDescending, key)
		gormOrderExpression = fmt.Sprintf(gormAscending, key)
	"k8s.io/apimachinery/pkg/util/sets"

func TestSortParameter_Nil(t *testing.T) {
	sortParameter, err := NewSortParameter(nil, nil)

	assert.NoError(t, err)
	assert.Nil(t, sortParameter)
}

func TestSortParameter_InvalidSortKey(t *testing.T) {
	_, err := NewSortParameter(&admin.Sort{
		Direction: admin.Sort_ASCENDING,
		Key:       "wrong",
	}, sets.NewString("name"))

	assert.EqualError(t, err, "invalid sort key 'wrong'")
}

func TestSortParameter_InvalidSortDirection(t *testing.T) {
	_, err := NewSortParameter(&admin.Sort{
		Direction: 2,
		Key:       "name",
	}, sets.NewString("name"))

	assert.EqualError(t, err, `invalid sort order specified: key:"name" direction:2 `)
}

	sortParameter, err := NewSortParameter(&admin.Sort{
	}, sets.NewString("name"))

	assert.NoError(t, err)
	sortParameter, err := NewSortParameter(&admin.Sort{
	}, sets.NewString("project"))

	assert.NoError(t, err)
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flytestdlib/contextutils"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"google.golang.org/grpc/codes"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.DescriptionEntityColumns)
	if err != nil {
		return nil, err

	"github.com/benbjohnson/clock"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils/labeled"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	"github.com/flyteorg/flyteadmin/auth"
	"github.com/flyteorg/flyteadmin/pkg/common"
	dataInterfaces "github.com/flyteorg/flyteadmin/pkg/data/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/resources"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	"github.com/flyteorg/flyteadmin/plugins"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.ExecutionColumns)
	if err != nil {
		return nil, err
	"fmt"
	"time"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/ptypes/wrappers"
	"github.com/stretchr/testify/assert"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/timestamppb"
	eventWriterMocks "github.com/flyteorg/flyteadmin/pkg/async/events/mocks"
	"github.com/flyteorg/flyteadmin/pkg/common"
	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
	commonTestUtils "github.com/flyteorg/flyteadmin/pkg/common/testutils"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/executions"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	managerInterfaces "github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
	managerMocks "github.com/flyteorg/flyteadmin/pkg/manager/mocks"
	"github.com/flyteorg/flyteadmin/pkg/runtime"
	"github.com/flyteorg/flyteadmin/plugins"
		assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "execution_domain",
		assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "execution_domain",
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
	if err != nil {
		return nil, err

	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
	if err != nil {
		return nil, err


	sortParameter, err := common.NewSortParameter(request.SortBy, models.LaunchPlanColumns)
	if err != nil {
		return nil, err

	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"google.golang.org/grpc/codes"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.NamedEntityColumns)
	if err != nil {
		return nil, err

	"fmt"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils/labeled"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
	eventWriter "github.com/flyteorg/flyteadmin/pkg/async/events/interfaces"
	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/shared"
	"github.com/flyteorg/flyteadmin/pkg/manager/impl/validation"

	sortParameter, err := common.NewSortParameter(sortBy, models.NodeExecutionColumns)
	if err != nil {
		return nil, err

	"github.com/flyteorg/flyteadmin/pkg/manager/impl/testutils"


	"github.com/flyteorg/flyteadmin/pkg/common"
	commonMocks "github.com/flyteorg/flyteadmin/pkg/common/mocks"
	dataMocks "github.com/flyteorg/flyteadmin/pkg/data/mocks"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
	repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "execution_domain",
	assert.NoError(t, err)
			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "execution_domain",

			Key:       "execution_domain",

	assert.NoError(t, err)
			assert.Equal(t, "execution_domain asc", input.SortParameter.GetGormOrderExpr())
			Key:       "execution_domain",
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"google.golang.org/grpc/codes"

	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
var alphabeticalSortParam, _ = common.NewSortParameter(&admin.Sort{
}, models.ProjectColumns)
	sortParameter, err := common.NewSortParameter(request.SortBy, models.ProjectColumns)
	if err != nil {
		return nil, err
	}
	if sortParameter == nil {
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"github.com/flyteorg/flytestdlib/promutils/labeled"
	"google.golang.org/grpc/codes"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.SignalColumns)
	if err != nil {
		return nil, err
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils/labeled"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	cloudeventInterfaces "github.com/flyteorg/flyteadmin/pkg/async/cloudevent/interfaces"
	notificationInterfaces "github.com/flyteorg/flyteadmin/pkg/async/notifications/interfaces"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskExecutionColumns)
	if err != nil {
		return nil, err
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/prometheus/client_golang/prometheus"
	"google.golang.org/grpc/codes"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskColumns)
	if err != nil {
		return nil, err


	sortParameter, err := common.NewSortParameter(request.SortBy, models.TaskColumns)
	if err != nil {
		return nil, err

	"fmt"
	"k8s.io/apimachinery/pkg/util/sets"
	"github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
var allowedJoinEntities = map[common.Entity]sets.String{
	common.Execution:           sets.NewString(common.Execution, common.LaunchPlan, common.Workflow, common.Task, common.AdminTag),
	common.LaunchPlan:          sets.NewString(common.LaunchPlan, common.Workflow),
	common.NodeExecution:       sets.NewString(common.NodeExecution, common.Execution),
	common.NodeExecutionEvent:  sets.NewString(common.NodeExecutionEvent),
	common.Task:                sets.NewString(common.Task),
	common.TaskExecution:       sets.NewString(common.TaskExecution, common.Task, common.Execution, common.NodeExecution),
	common.Workflow:            sets.NewString(common.Workflow),
	common.NamedEntity:         sets.NewString(common.NamedEntity),
	common.NamedEntityMetadata: sets.NewString(common.NamedEntityMetadata),
	common.Project:             sets.NewString(common.Project),
	common.Signal:              sets.NewString(common.Signal),
	common.AdminTag:            sets.NewString(common.AdminTag),
}

var entityColumns = map[common.Entity]sets.String{
	common.Execution:           models.ExecutionColumns,
	common.LaunchPlan:          models.LaunchPlanColumns,
	common.NodeExecution:       models.NodeExecutionColumns,
	common.NodeExecutionEvent:  models.NodeExecutionEventColumns,
	common.Task:                models.TaskColumns,
	common.TaskExecution:       models.TaskExecutionColumns,
	common.Workflow:            models.WorkflowColumns,
	common.NamedEntity:         models.NamedEntityColumns,
	common.NamedEntityMetadata: models.NamedEntityMetadataColumns,
	common.Project:             models.ProjectColumns,
	common.Signal:              models.SignalColumns,
	common.AdminTag:            models.AdminTagColumns,
}

		joinEntities, ok := allowedJoinEntities[primaryEntity]
		if !ok {
			return nil, fmt.Errorf("unsupported entity '%s'", primaryEntity)
		}

		if !joinEntities.Has(referencedEntity) {
			return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "'%s' entity is not allowed in filters", referencedEntity)
		}

		if !entityColumns[referencedEntity].Has(field) {
			return nil, errors.NewFlyteAdminErrorf(codes.InvalidArgument, "'%s.%s' is invalid filter", referencedEntity, field)
		}

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
func Test_ParseFilters_Success(t *testing.T) {
	filterExpression := "eq(project, flytesnacks)+ne(domain, development)+value_in(type, 4;5;6)"


	require.Len(t, taskFilters, 3)
	assert.Equal(t, "project = ?", actualFilterExpression.Query)
	assert.Equal(t, "flytesnacks", actualFilterExpression.Args)
	assert.Equal(t, "domain <> ?", actualFilterExpression.Query)
	assert.Equal(t, "development", actualFilterExpression.Args)
	assert.Equal(t, "type in (?)", actualFilterExpression.Query)
}

func Test_ParseFilters_InvalidFunction(t *testing.T) {
	filterExpression := "invalid_function(type,bar)"

	_, err := ParseFilters(filterExpression, common.Task)
func Test_ParseFilters_UnsupportedEntity(t *testing.T) {
	filterExpression := "eq(foo, 123)"

	_, err := ParseFilters(filterExpression, "wrong")

	assert.EqualError(t, err, "unsupported entity 'wrong'")
}

func Test_ParseFilters_InvalidJoinEntity(t *testing.T) {
	filterExpression := "eq(project.name, 123)"

	_, err := ParseFilters(filterExpression, common.Workflow)

	assert.EqualError(t, err, "'p' entity is not allowed in filters")
}

func Test_ParseFilters_InvalidFilter(t *testing.T) {
	filterExpression := "eq(foo, 123)"

	_, err := ParseFilters(filterExpression, common.Task)

	assert.EqualError(t, err, "'t.foo' is invalid filter")
}

func Test_AddRequestFilters(t *testing.T) {
		"ne(cluster, TheWorst)+eq(workflow.name, workflow)", common.Execution, make([]common.InlineFilter, 0))

	assert.NoError(t, err)
	require.Len(t, filters, 2)

	assert.NoError(t, err)
	assert.Equal(t, "cluster <> ?", expression.Query)
	assert.NoError(t, err)
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	compiler "github.com/flyteorg/flytepropeller/pkg/compiler/common"
	"github.com/flyteorg/flytestdlib/logger"
	"github.com/flyteorg/flytestdlib/promutils"
	"github.com/flyteorg/flytestdlib/storage"
	"github.com/golang/protobuf/ptypes"
	"github.com/prometheus/client_golang/prometheus"
	"google.golang.org/grpc/codes"

	sortParameter, err := common.NewSortParameter(request.SortBy, models.WorkflowColumns)
	if err != nil {
		return nil, err


	sortParameter, err := common.NewSortParameter(request.SortBy, models.WorkflowColumns)
	if err != nil {
		return nil, err

	"sync"

	"google.golang.org/grpc/codes"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
	"k8s.io/apimachinery/pkg/util/sets"

func modelColumns(v any) sets.String {
	s, err := schema.Parse(v, &sync.Map{}, schema.NamingStrategy{})
	if err != nil {
		panic(err)
	}
	return sets.NewString(s.DBNames...)
}
	"gorm.io/gorm"
	"github.com/flyteorg/flyteadmin/pkg/common"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/flyteorg/flytestdlib/promutils"

	mocket "github.com/Selvatico/go-mocket"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	mockQuery := GlobalMock.NewMock().WithQuery(`execution_name asc`)
	sortParameter, err := common.NewSortParameter(&admin.Sort{
		Key:       "execution_name",
	}, models.ExecutionColumns)
	require.NoError(t, err)

	_, err = executionRepo.List(context.Background(), interfaces.ListResourceInput{

	mockQuery := GlobalMock.NewMock().WithQuery(`execution_name asc`)
	sortParameter, err := common.NewSortParameter(&admin.Sort{
		Key:       "execution_name",
	}, models.ExecutionColumns)
	require.NoError(t, err)


	"github.com/flyteorg/flytestdlib/logger"
	"gorm.io/gorm"

	mocket "github.com/Selvatico/go-mocket"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	"github.com/stretchr/testify/assert"
	sortParameter, _ := common.NewSortParameter(&admin.Sort{
	}, models.LaunchPlanColumns)
	"github.com/flyteorg/flytestdlib/promutils"
	"gorm.io/gorm"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"

	sortParameter, _ := common.NewSortParameter(&admin.Sort{
	}, models.NamedEntityColumns)
	"github.com/flyteorg/flytestdlib/promutils"
	"gorm.io/gorm"

	"gorm.io/gorm"
	mocket "github.com/Selvatico/go-mocket"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"google.golang.org/grpc/codes"
	"gorm.io/gorm"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	mockQuery.WithQuery(`execution_project desc`)
	sortParameter, err := common.NewSortParameter(&admin.Sort{
		Key:       "execution_project",
	}, models.NodeExecutionColumns)
	require.NoError(t, err)

	_, err = nodeExecutionRepo.List(context.Background(), interfaces.ListResourceInput{

	"google.golang.org/grpc/codes"
	flyteAdminErrors "github.com/flyteorg/flyteadmin/pkg/errors"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"

var alphabeticalSortParam, _ = common.NewSortParameter(&admin.Sort{
}, models.ProjectColumns)

	assert.NoError(t, err)
	mocket "github.com/Selvatico/go-mocket"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
	"github.com/flyteorg/flytestdlib/promutils"
	"google.golang.org/grpc/codes"
	"gorm.io/gorm"

	"gorm.io/gorm"
	mocket "github.com/Selvatico/go-mocket"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
	"github.com/stretchr/testify/assert"
	"gorm.io/gorm"
	"github.com/stretchr/testify/assert"

	sortParameter, _ := common.NewSortParameter(&admin.Sort{
	}, models.TaskColumns)

	flyteAdminDbErrors "github.com/flyteorg/flyteadmin/pkg/repositories/errors"
	"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
	"github.com/flyteorg/flyteadmin/pkg/repositories/models"
	"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
	mockScope "github.com/flyteorg/flytestdlib/promutils"
	"github.com/stretchr/testify/assert"

	sortParameter, _ := common.NewSortParameter(&admin.Sort{
	}, models.WorkflowColumns)
import (
	"sync"
	"time"

	"gorm.io/gorm/schema"
	"k8s.io/apimachinery/pkg/util/sets"
)

func modelColumns(v any) sets.String {
	s, err := schema.Parse(v, &sync.Map{}, schema.NamingStrategy{})
	if err != nil {
		panic(err)
	}
	return sets.NewString(s.DBNames...)
}

var DescriptionEntityColumns = modelColumns(DescriptionEntity{})

var (
	ExecutionColumns = modelColumns(Execution{})
	AdminTagColumns  = modelColumns(AdminTag{})
)

var LaunchPlanColumns = modelColumns(LaunchPlan{})

var (
	NamedEntityColumns         = modelColumns(NamedEntity{})
	NamedEntityMetadataColumns = modelColumns(NamedEntityMetadata{})
)

var NodeExecutionColumns = modelColumns(NodeExecution{})

var NodeExecutionEventColumns = modelColumns(NodeExecutionEvent{})

var ProjectColumns = modelColumns(Project{})

var SignalColumns = modelColumns(Signal{})

var TaskColumns = modelColumns(Task{})

var TaskExecutionColumns = modelColumns(TaskExecution{})

var WorkflowColumns = modelColumns(Workflow{})