Skip to content

fix(jira): convert scope config bytea columns to json on postgres - #9416

Open
DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/jira-scope-config-json
Open

DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/jira-scope-config-json

Conversation

@DoDiODev

Copy link
Copy Markdown
Contributor

Summary

On PostgreSQL, saving a Jira scope config with a remote link pattern
(Cross-domain → Connect Jira issues and commits via Jira issues' remote
links …
) fails:

ERROR: invalid input syntax for type bytea (SQLSTATE 22P02) (500)

type_mappings and remotelink_repo_pattern of _tool_jira_scope_configs
were created from json.RawMessage (20220716_add_init_tables,
20230223_add_repo_pattern) and therefore became bytea on PostgreSQL. The
current model writes both with gorm:"type:json;serializer:json", i.e. as
JSON text. PostgreSQL parses that text as bytea escape input, so any
backslash breaks it — and the regex generated by /plugins/jira/generate-regex
always contains \S+ and \w{40}. type_mappings only works by accident
because it contains no backslashes.

This PR adds a migration that converts both columns to json on PostgreSQL
(convert_from(col, 'UTF8')::json; empty values left by
20230609_clear_repo_pattern become NULL). It only runs when the columns
are still bytea. MySQL (longblob) is not affected and left unchanged.

Does this close any open issues?

Closes #8275 (closed as stale, still reproducible on main).

Screenshots

n/a

Other Information

Verified manually against a fresh PostgreSQL 18 with go run server/main.go:

  • without the fix: POST /plugins/jira/connections/1/scope-configs with a
    remote link pattern → 500 invalid input syntax for type bytea;
  • with the fix: migration converts both columns to json, existing rows
    (NULL, empty, valid JSON) are preserved, POST/PATCH with the pattern
    return 200 and GET returns pattern and type mappings unchanged.

Also applied to an existing PostgreSQL instance with real Jira data: the
migration converted both columns, and all remote link patterns could then be
saved through the config UI.

gofmt, go vet and make migration-script-lint pass. CI on the fork
(same jobs as upstream, PostgreSQL 18.7 / MySQL 8.4):
https://github.com/DoDiODev/devlake/actions/runs/44511264970 (16/16 green).

type_mappings and remotelink_repo_pattern of _tool_jira_scope_configs were
created from json.RawMessage and became bytea on PostgreSQL, while the
model writes them as JSON text. PostgreSQL parses that text as bytea
escape input, so saving a remote link pattern (its generated regex
contains backslashes such as \S+) fails with
"invalid input syntax for type bytea (SQLSTATE 22P02)".

Convert both columns to json on PostgreSQL; empty values become NULL.
MySQL is not affected and left unchanged.

Fixes apache#8275

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: DoDiODev <DoDiDev@proton.me>
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.

[Bug][Jira] Saving regex pattern fails

1 participant