From 513a4669cc4c258d15333b51eead7e1a4d6b8104 Mon Sep 17 00:00:00 2001 From: Kyriakos Z <3829551+koox00@users.noreply.github.com> Date: Wed, 26 Jan 2022 11:36:33 +0200 Subject: [PATCH] MM-41066: fixes replies when binary_parameters=yes (#19404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MM-41066: fixes replies when binary_parameters=yes Migrating post_store from gorp to sqlx breaks replies on threads. Why? Participants is a jsonb field and when binary_parameters is set to 'yes' it is failing to insert because it needs the version (1) to be prepended to the bytes array ([]byte{0x01}). The easiest fix on this is to cast to a string when inserting. There is a drawback though, non utf8 characters would be replaced by the question mark icon �. This commit does exactly that, casts StringArray to a string. * Adds a comment * Removes unnecessary conversion Co-authored-by: Mattermod --- model/utils.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model/utils.go b/model/utils.go index 2844f7d5f6..92b6c35846 100644 --- a/model/utils.go +++ b/model/utils.go @@ -76,7 +76,12 @@ func (sa StringArray) Equals(input StringArray) bool { // Value converts StringArray to database value func (sa StringArray) Value() (driver.Value, error) { - return json.Marshal(sa) + j, err := json.Marshal(sa) + if err != nil { + return nil, err + } + // non utf8 characters are not supported + return string(j), err } // Scan converts database column value to StringArray