From 9e6bb1a8a34d3a861b591d0ac772310c046700ff Mon Sep 17 00:00:00 2001 From: Sean Egan Date: Tue, 1 Mar 2022 09:28:38 -0700 Subject: [PATCH] Update gorm query to fix ordering bug (#468) --- server/registry/internal/storage/get.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/registry/internal/storage/get.go b/server/registry/internal/storage/get.go index 4ea2fa128..d4ff60b05 100644 --- a/server/registry/internal/storage/get.go +++ b/server/registry/internal/storage/get.go @@ -64,10 +64,10 @@ func (c *Client) GetSpec(ctx context.Context, name names.Spec) (*models.Spec, er Where("api_id = ?", name.ApiID). Where("version_id = ?", name.VersionID). Where("spec_id = ?", name.SpecID). - Order("revision_create_time") + Order("revision_create_time desc") v := new(models.Spec) - if err := op.Last(v).Error; err == gorm.ErrRecordNotFound { + if err := op.First(v).Error; err == gorm.ErrRecordNotFound { return nil, status.Errorf(codes.NotFound, "%q not found in database", name) } else if err != nil { return nil, status.Error(codes.Internal, err.Error()) @@ -114,10 +114,10 @@ func (c *Client) GetDeployment(ctx context.Context, name names.Deployment) (*mod Where("project_id = ?", name.ProjectID). Where("api_id = ?", name.ApiID). Where("deployment_id = ?", name.DeploymentID). - Order("revision_create_time") + Order("revision_create_time desc") v := new(models.Deployment) - if err := op.Last(v).Error; err == gorm.ErrRecordNotFound { + if err := op.First(v).Error; err == gorm.ErrRecordNotFound { return nil, status.Errorf(codes.NotFound, "%q not found in database", name) } else if err != nil { return nil, status.Error(codes.Internal, err.Error())