Skip to content

fix(gitlab): add missing commit_updated_at column used by the MR incremental filter - #9046

Open
DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/gitlab-mr-commit-updated-at
Open

fix(gitlab): add missing commit_updated_at column used by the MR incremental filter#9046
DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/gitlab-mr-commit-updated-at

Conversation

@DoDiODev

Copy link
Copy Markdown
Contributor

fix(gitlab): add missing commit_updated_at column used by the MR incremental filter

Summary

#8959 changed GetMergeRequestsIterator (backend/plugins/gitlab/tasks/shared.go) to
filter merge requests by

GREATEST(gmr.gitlab_updated_at, COALESCE(gmr.commit_updated_at, gmr.gitlab_updated_at)) > ?

but commit_updated_at does not exist on _tool_gitlab_merge_requests. There is no field
on the GitlabMergeRequest model, no migration script, and no code writing the value —
the only occurrences of the identifier in the whole repository are the three lines added
by that PR.

Consequently every incremental run of Collect MR Notes — the only caller passing a
stateful collector, mr_commit_collector.go passes nil — fails with:

subtask Collect MR Notes ended unexpectedly
  Error 1054 (42S22): Unknown column 'gmr.commit_updated_at' in 'where clause'

Approach

Rather than reverting #8959, this PR makes the intended behaviour actually work:

  • add CommitUpdatedAt *time.Time to GitlabMergeRequest
  • add migration script 20260812_add_mr_commit_updated_at.go (registered in register.go)
  • maintain the column in ExtractApiMergeRequestsCommits: after extraction it is set to
    the latest commit_authored_date of the MR's commits, scoped to the current
    connection/project
  • the filter in GetMergeRequestsIterator is left as introduced by fix(gitlab): always re-collect MR commits regardless of MR updated_at… #8959 and now resolves
    against a real column, so MRs that received new commits without their own updated_at
    being bumped (e.g. force-pushes) are picked up again

Testing

  • make migration-script-lint
  • go test ./plugins/gitlab/e2e/ -run TestGitlabMrCommitDataFlow — green on MySQL 8
    and PostgreSQL 14; the extractor's UPDATE ... SET ... = (SELECT MAX(...)) and the
    GREATEST/COALESCE filter behave identically on both engines
  • go test ./plugins/ -run TestTableInfo

Notes

The GREATEST(...) expression returns NULL on MySQL when gitlab_updated_at is NULL,
so such MRs stay excluded — same as before #8959, where gitlab_updated_at > ? also
evaluated to NULL. No behaviour change there.

…tal filter

apache#8959 changed `GetMergeRequestsIterator` to filter merge requests by
`GREATEST(gmr.gitlab_updated_at, COALESCE(gmr.commit_updated_at, gmr.gitlab_updated_at))`,
but `commit_updated_at` does not exist on `_tool_gitlab_merge_requests`:
there is neither a model field nor a migration script, and nothing ever
writes the value.

As a result every incremental "Collect MR Notes" run (the only caller that
passes a stateful collector; the MR commit collector passes nil) aborts with:

    Error 1054 (42S22): Unknown column 'gmr.commit_updated_at' in 'where clause'

This makes the intended behaviour actually work instead of reverting it:

* add `CommitUpdatedAt` to `GitlabMergeRequest` plus a migration script
* maintain the column in the MR commit extractor, setting it to the latest
  authored date of the MR's commits, so MRs that received new commits without
  their own `updated_at` being bumped (e.g. force-pushes) are picked up again
* the collector filter is unchanged and now resolves against a real column

Verified on MySQL 8 and PostgreSQL 14 (extractor UPDATE and the GREATEST
filter produce identical results on both).
@DoDiODev
DoDiODev force-pushed the pr/gitlab-mr-commit-updated-at branch from 5a7923d to 2ffa333 Compare August 12, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant