Skip to content

Guard code path to execute only if attribute exists

Andreas Brandl requested to merge ab/fix-total-tuple-count-bug into master

What does this MR do?

This is a fix for #327447 (closed).

We introduced the total_tuple_count attribute with !58675 (merged).

In two earlier migrations, we already called queue_batched_background_migration. For the schema version present at these earlier migrations, there is no such column total_tuple_count yet. Hence the migration fails, as shown in #327447 (closed) when run from scratch.

This did not surface in CI because the code path was guarded with Gitlab.dev_env_or_com? with the intention of hitting GitLab.com only. However, that also prevented the code path from being triggered in CI, which would have surfaced the problem (see https://gitlab.com/gitlab-org/gitlab/-/jobs/1171452023). This has been fixed here, too.

The essential fix here is to guard the code path working with total_tuple_count with a schema version check. Instead of relying on the schema version, we just check if the attribute exists on the model.

Edited by Andreas Brandl

Merge request reports