You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug][Webhook] Posting by project name: the first call returns 404 and drops the payload, and the scheduled sync ignores the new connection #9418
I had searched in the issues and found no similar issues.
What happened
The endpoints that post to a webhook by project name (POST /plugins/webhook/projects/:projectName/deployments, and the issues and pull_requests equivalents added in #8915) create the webhook connection on the first call through getOrCreateConnection (backend/plugins/webhook/api/deployments.go). That function has two problems.
1. The first call returns 404 and the payload is not stored. err is first set by findByProjectName, which returns a not-found error when the connection does not exist yet. Inside the if err != nil block, projectOutput, err := services.GetProject(projectName) declares a new err that shadows the outer one. The function then ends with return connection, err, false, which returns the original not-found error. postDeployments (and postIssue, postPullRequests) return early when err != nil, so the caller gets a 404 although the connection and its blueprint connection were created, and the deployment sent in that first call is never stored. Sending the same payload again works.
2. The scheduled sync does not see the new connection until the blueprint is saved or the server restarts.
The connection is attached to the project's blueprint with a direct dal.Create(blueprintConnection). The cron job, however, runs a copy of the blueprint that reloadBlueprint loaded into memory (BlueprintJob{blueprint} in backend/server/services/blueprint.go), and nothing reloads it here. A manual "Collect Data" reads the blueprint from the database and includes the webhook, so everything looks fine at first. The next scheduled run plans from the stale copy, rebuilds project_mapping without the webhook's cicd_scopes/boards/repos rows, and the posted deployments stop counting for the project (DORA metrics drop) until someone saves the blueprint or restarts DevLake.
What do you expect to happen
The first call stores the payload and returns 200, like the following ones.
After the connection is attached, scheduled runs include it.
How to reproduce
Create a project with a blueprint and a daily schedule, without any webhook connection.
POST /api/rest/plugins/webhook/projects/<project>/deployments with a valid deployment. It returns 404, but a connection named <project>_deployments appears in the blueprint.
Send the same request again: it returns 200 and the deployment is stored.
Trigger "Collect Data" manually: the deployment is mapped to the project (project_mapping has webhook:<id> rows).
Wait for the next scheduled run: project_mapping no longer has the webhook:<id> rows, and the deployment no longer counts for the project.
Save the blueprint without changes (PATCH /blueprints/<id>) and trigger again: the rows come back and later scheduled runs keep them.
Anything else
Possible fix, both in getOrCreateConnection:
Avoid the shadowing (for example projectOutput, getErr := services.GetProject(projectName)) and return nil as the error once the connection has been created.
After dal.Create(blueprintConnection), reload the scheduled copy of the blueprint: either attach the connection through services.PatchBlueprint (which saves and reloads it, like the UI does) instead of inserting the row directly, or call services.ReloadBlueprints() afterwards.
Workaround: after the first call, send it again, and save the blueprint once (PATCH /blueprints/<id> with its current connections) so the scheduler picks up the new connection.
I'd like to work on this. Plan: stop the inner err from shadowing the not-found error in getOrCreateConnection so the first call stores the payload and returns 200, and reload the blueprint's scheduled job after the connection is attached so cron runs include it. I'll add tests for both and link the PR here.
PR is up: #9426. It fixes both parts: the first call now stores the payload and returns 200, and the blueprint's scheduled job is reloaded after the connection is attached.
Activity
shaynhornik commentedon Nov 21, 2026
I'd like to work on this. Plan: stop the inner
errfrom shadowing the not-found error ingetOrCreateConnectionso the first call stores the payload and returns 200, and reload the blueprint's scheduled job after the connection is attached so cron runs include it. I'll add tests for both and link the PR here.shaynhornik commentedon Nov 21, 2026
PR is up: #9426. It fixes both parts: the first call now stores the payload and returns 200, and the blueprint's scheduled job is reloaded after the connection is attached.