Add validation for missing project/user in Ci::CreatePipelineService
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
Following up on the discussion in !200986 (merged), we should add validation for missing projects and users in Ci::CreatePipelineService
as well, in addition to the existing guards in CreatePipelineWorker
.
Background
In !200986 (merged), we added guards in CreatePipelineWorker
to handle missing projects and users gracefully:
project = Project.find_by_id(project_id)
return unless project
user = User.find_by_id(user_id)
return unless user
Proposal
@allison.browne suggested that we should also add validation in the Ci::CreatePipelineService
itself. The benefits would be:
-
Better error handling: We could use
error()
without a failure reason to populate::Ci::PipelineCreation::Requests
with an error, allowing users to see why the latest pipeline for a project or MR wasn't created. -
Broader protection: This would handle the condition from other callers of
Ci::CreatePipelineService
, not just the worker. -
Consistent behavior: Using
error(msg)
in the pipeline creation service without afailure_reason
will not persist the pipeline, having the same effect as not creating a pipeline.
Implementation Notes
- Add validation in
Ci::CreatePipelineService
to check that both project and user exist - Use the service's
error()
method to provide meaningful feedback when they don't exist - Ensure the error doesn't persist a failed pipeline (no
failure_reason
) - Keep the existing validation in
CreatePipelineWorker
as well
Related
- Original MR: !200986 (merged)
- Discussion: !200986 (comment 2683423302)