Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: nil pointer for env (#4171)

ecmadao985520b3a418
diff --git a/server/api/v1/environment_service.go b/server/api/v1/environment_service.go
index 19851f027d..4c34dbf5fa 100644
--- a/server/api/v1/environment_service.go
+++ b/server/api/v1/environment_service.go
@@ -90,6 +90,7 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, request *v1p
ResourceID: request.EnvironmentId,
Title: request.Environment.Title,
Order: request.Environment.Order,
+ Protected: request.Environment.Tier == v1pb.EnvironmentTier_PROTECTED,
},
principalID,
)
diff --git a/store/environment.go b/store/environment.go
index 9b41deabaf..75b7b6ebc4 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -226,6 +226,9 @@ func (s *Store) GetEnvironmentV2(ctx context.Context, find *FindEnvironmentMessa
if err != nil {
return nil, err
}
+ if environment == nil {
+ return nil, nil
+ }
if err := tx.Commit(); err != nil {
return nil, FormatError(err)
diff --git a/store/instance.go b/store/instance.go
index 24217257bf..8f767ca27a 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -857,6 +857,10 @@ func (s *Store) CreateInstanceV2(ctx context.Context, environmentID string, inst
if err != nil {
return nil, err
}
+ if environment == nil {
+ return nil, common.Errorf(common.NotFound, "environment %s not found", environmentID)
+ }
+
var instanceID int
if err := tx.QueryRowContext(ctx, `
INSERT INTO instance (
@@ -964,6 +968,9 @@ func (s *Store) UpdateInstanceV2(ctx context.Context, patch *UpdateInstanceMessa
if err != nil {
return nil, err
}
+ if environment == nil {
+ return nil, common.Errorf(common.NotFound, "environment %s not found", patch.EnvironmentID)
+ }
args = append(args, patch.ResourceID, environment.UID)