Skip to content

Fix null argument handling in background migration Rake task

Stan Hu requested to merge sh-background-migration-double-parsing into master

!80375 (merged) added an additional Gitlab::Json.parse call to the gitlab:background_migrations:finalize Rake task. This worked fine when the string just had strings or numbers:

parsed = Gitlab::Json.parse('[["id1", "id2"]]')
=> [["id1", "id2"]]
Gitlab::Json.parse(parsed)
=> [["id1", "id2"]]

However, notice what happens if you substitute a null value:

parsed = Gitlab::Json.parse('[["id1", null]]')
=> [["id1", nil]]
Gitlab::Json.parse(parsed)
JSON::ParserError: not a number or other value ([0][1]) at line 1, column 9 [parse.c:418]

Gitlab::Json.parse calls to_s on the input. In the first case, calling to_s again on the parsed array is fine since the strings can be parsed again. However, nil can't be parsed because JSON expects null instead.

In addition, the migration helpers generated incorrect instructions for nil arguments. We now use to_json to show null instead of nil.

Edited by Stan Hu

Merge request reports