Prevent parent overwrites during upserts

This commit is contained in:
Chris Roberts 2023-06-12 09:20:29 -07:00
parent 02f844a05d
commit dcb517e1fb
2 changed files with 12 additions and 4 deletions

View File

@ -89,6 +89,7 @@ func (p *Project) BeforeSave(tx *gorm.DB) error {
return err
}
}
if err := p.Validate(tx); err != nil {
return err
}
@ -358,8 +359,11 @@ func (s *State) ProjectPut(
return nil, lookupErrorToStatus("project", err)
}
// Make sure we don't have a nil value
if err != nil {
// If a project is found, remove the basis
// ref to prevent update attempts
if project != nil {
p.Basis = nil
} else {
project = &Project{}
}

View File

@ -394,8 +394,12 @@ func (s *State) TargetPut(
return nil, lookupErrorToStatus("target", err)
}
// Make sure we don't have a nil
if err != nil {
// If a target is found, remove the project
// ref to prevent update attempts
if target != nil {
t.Project = nil
} else {
// Otherwise, init target for the decode
target = &Target{}
}