{"record":{"id":"2d7cb5e004e8342d","repo":"semaphoreui/semaphore","slug":"s-is-required-for-owner-q","errorCode":null,"errorMessage":"%s is required for owner %q","messagePattern":"(.+?) is required for owner %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db/Store.go","lineNumber":361,"sourceCode":"\t\treturn nil\n\t}\n\n\tvar value *int\n\tvar name string\n\n\tswitch o.Owner {\n\tcase AccessKeyVariable, AccessKeyEnvironment:\n\t\tvalue, name = o.EnvironmentID, \"environment_id\"\n\tcase AccessKeySecretStorage:\n\t\tvalue, name = o.StorageID, \"storage_id\"\n\tcase AccessKeyTaskSecret:\n\t\tvalue, name = o.TaskID, \"task_id\"\n\tdefault:\n\t\treturn nil\n\t}\n\n\tif value == nil {\n\t\treturn fmt.Errorf(\"%s is required for owner %q\", name, o.Owner)\n\t}\n\n\treturn nil\n}\n\n// AccessKeyManager handles access key-related operations\ntype AccessKeyManager interface {\n\tGetAccessKey(projectID int, accessKeyID int) (AccessKey, error)\n\tGetAccessKeyRefs(projectID int, accessKeyID int) (ObjectReferrers, error)\n\tGetAccessKeys(projectID int, options GetAccessKeyOptions, params RetrieveQueryParams) ([]AccessKey, error)\n\tUpdateAccessKey(accessKey AccessKey) error\n\tCreateAccessKey(accessKey AccessKey) (AccessKey, error)\n\tDeleteAccessKey(projectID int, accessKeyID int) error\n\t// GetTaskAccessKey returns the AccessKeyTaskSecret-owned key of a task\n\t// (survey secret variables), or ErrNotFound when the task has none.\n\tGetTaskAccessKey(projectID int, taskID int) (AccessKey, error)\n\t// DeleteTaskAccessKeys removes all AccessKeyTaskSecret-owned keys of a task.\n\t// Deleting for a task without such keys is not an error.","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/db/Store.go#L343-L379","documentation":"When storing an object owned by another entity (project, environment, task, etc.), the corresponding owner ID field must be set. If the required ID value is nil, the store returns '<field> is required for owner \"<owner>\"', naming the missing field (e.g. task_id) and the owner kind.","triggerScenarios":"Creating/storing an owned object via the ObjectProps-based APIs with an Owner such as 'task' but leaving the corresponding ID field (e.g. TaskID) nil.","commonSituations":"Programmatic resource creation that sets Owner but forgets the ID; struct literals built dynamically where optional fields were skipped; API payloads missing the owner ID field.","solutions":["Set the required owner ID field (e.g. TaskID) before saving the object","Only set Owner when you actually have the corresponding ID; otherwise leave Owner empty","Validate the request payload for the owner ID before mapping it into the store object"],"exampleFix":"// before\no := db.ObjectProps{Owner: \"task\"}\nstore.Create(o)\n// after\no := db.ObjectProps{Owner: \"task\", TaskID: &task.ID}\nstore.Create(o)","handlingStrategy":"validation","validationCode":"func validateOwner(o *db.ObjectProps) error {\n    switch o.Owner {\n    case \"task\":\n        if o.TaskID == nil {\n            return errors.New(\"task_id is required for owner 'task'\")\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := store.Create(o); err != nil {\n    if strings.Contains(err.Error(), \"is required for owner\") {\n        return fmt.Errorf(\"payload missing owner id: %w\", err)\n    }\n    return err\n}","preventionTips":["Only set Owner when the matching ID field is populated","Validate payloads for owner IDs before mapping into store objects","Build owned objects via constructors that pair Owner with its ID"],"tags":["database","validation","owner"],"backgroundTag":"missing-required-argument","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}