Skip to content

Fix ambiguous string concatenation on CleanupProjectsWithMissingNamespace

What does this MR do?

A regression has been reported on at least one environments when the db/post_migrate/20200511083541_cleanup_projects_with_missing_namespace.rb post-migration runs:

== 20200511083541 CleanupProjectsWithMissingNamespace: migrating ==============
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

PG::AmbiguousFunction: ERROR:  operator is not unique: text || integer
LINE 8: name = name || '_' || id,
                           ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.

... ...

(For reference, this migration was introduced with !31675 (merged))

We can not reproduce this behavior on Gitlab's Production replica (where the migration run successfully either way) or a local Postgres 11.7.

String concatenation between a string and a non string is valid since PostgreSQL 8 and text || text || integer should not be ambiguous:

https://www.postgresql.org/docs/11/functions-string.html

| Function                                     | Return Type | Description                                    | Example            | Result     |
|----------------------------------------------|-------------|------------------------------------------------|--------------------|------------|
| string || string                             | text        | String concatenation                           | 'Post' || 'greSQL' | PostgreSQL |
| string || non-string or non-string || string | text        | String concatenation with one non-string input | 'Value: ' || 42    | Value: 42  |

The only case I can think of is that there is some Postgres extension that we don't use in GitLab.com that overloads the || operator and makes the operation ambiguous.

Either way, to solve this issue for all Postgres environments, a fix is introduced that casts the id (integer) to a text to make sure that the concatenation is always between text values.

Related issue: #219582 (closed)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading