Skip to content

Commit

Permalink
Fix audio null value
Browse files Browse the repository at this point in the history
If a message was inserted before the migration the field
audio_duration_ms would be set to NULL, and would not be serialized into
go correctly, as uint is non-nullable.
this commit fixes the issue by calling COALESCE on the value.
  • Loading branch information
cammellos committed Jul 30, 2020
1 parent ec39bef commit e6ae440
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.56.2
0.56.3
2 changes: 1 addition & 1 deletion protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string {
m1.sticker_pack,
m1.sticker_hash,
m1.image_base64,
m1.audio_duration_ms,
COALESCE(m1.audio_duration_ms,0),
m1.audio_base64,
m1.command_id,
m1.command_value,
Expand Down
22 changes: 22 additions & 0 deletions protocol/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,25 @@ func insertMinimalMessage(p sqlitePersistence, id string) error {
From: "me",
}})
}

// Regression test making sure that if audio_duration_ms is null, no error is thrown
func TestMessagesAudioDurationMsNull(t *testing.T) {
db, err := openTestDB()
require.NoError(t, err)
p := sqlitePersistence{db: db}
id := "message-id-1"

err = insertMinimalMessage(p, id)
require.NoError(t, err)

_, err = p.db.Exec("UPDATE user_messages SET audio_duration_ms = NULL")
require.NoError(t, err)

m, err := p.MessagesByIDs([]string{id})
require.NoError(t, err)
require.Len(t, m, 1)

m, _, err = p.MessageByChatID("chat-id", "", 10)
require.NoError(t, err)
require.Len(t, m, 1)
}

0 comments on commit e6ae440

Please sign in to comment.