From d911f7fbeaa03ba361554db2a9e2e85a9c7323ba Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Wed, 30 Aug 2023 11:12:33 +0200 Subject: [PATCH] fix: update gpb library to fix type error This fixes a bug in the protobuf schema registry functionality. Before this fix one would get a badarith error if one tried to assign a float value to an uint64 field. However, this commit fixes this by upgrading gpb so we instead will get a gpb_type_error which is what we want. Fixes: https://emqx.atlassian.net/browse/EMQX-10775 --- apps/emqx_schema_registry/rebar.config | 2 +- .../test/emqx_schema_registry_SUITE.erl | 15 ++++++++++++++- mix.exs | 2 +- rebar.config | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/emqx_schema_registry/rebar.config b/apps/emqx_schema_registry/rebar.config index 9924100bc..d604b89d9 100644 --- a/apps/emqx_schema_registry/rebar.config +++ b/apps/emqx_schema_registry/rebar.config @@ -6,7 +6,7 @@ {emqx_utils, {path, "../emqx_utils"}}, {emqx_rule_engine, {path, "../emqx_rule_engine"}}, {erlavro, {git, "https://github.com/klarna/erlavro.git", {tag, "2.9.8"}}}, - {gpb, "4.19.7"} + {gpb, "4.19.9"} ]}. {shell, [ diff --git a/apps/emqx_schema_registry/test/emqx_schema_registry_SUITE.erl b/apps/emqx_schema_registry/test/emqx_schema_registry_SUITE.erl index 0db2ea3c6..e2a696428 100644 --- a/apps/emqx_schema_registry/test/emqx_schema_registry_SUITE.erl +++ b/apps/emqx_schema_registry/test/emqx_schema_registry_SUITE.erl @@ -42,7 +42,8 @@ sparkplug_tests() -> [ t_sparkplug_decode, t_sparkplug_encode, - t_sparkplug_decode_encode_with_message_name + t_sparkplug_decode_encode_with_message_name, + t_sparkplug_encode_float_to_uint64_key ]. init_per_suite(Config) -> @@ -847,6 +848,18 @@ t_sparkplug_encode(_Config) -> ?assertMatch(#{data := ExpectedRuleOutput}, Res), ok. +t_sparkplug_encode_float_to_uint64_key(_Config) -> + %% Test that the following bug is fixed: + %% https://emqx.atlassian.net/browse/EMQX-10775 + %% When one assign a float value to a uint64 key, one should get a + %% gpb_type_error and not a badarith error + wait_for_sparkplug_schema_registered(), + ?assertException( + error, + {gpb_type_error, _}, + emqx_rule_funcs:sparkplug_encode(#{<<"seq">> => 1.5}) + ). + t_sparkplug_decode_encode_with_message_name(_Config) -> SQL = << diff --git a/mix.exs b/mix.exs index d57cedc2b..585abd230 100644 --- a/mix.exs +++ b/mix.exs @@ -93,7 +93,7 @@ defmodule EMQXUmbrella.MixProject do # in conflict by cowboy_swagger and cowboy {:ranch, github: "emqx/ranch", tag: "1.8.1-emqx", override: true}, # in conflict by grpc and eetcd - {:gpb, "4.19.7", override: true, runtime: false}, + {:gpb, "4.19.9", override: true, runtime: false}, {:hackney, github: "emqx/hackney", tag: "1.18.1-1", override: true}, # set by hackney (dependency) {:ssl_verify_fun, "1.1.6", override: true}, diff --git a/rebar.config b/rebar.config index 2d605c18f..197d06a67 100644 --- a/rebar.config +++ b/rebar.config @@ -53,7 +53,7 @@ [ {lc, {git, "https://github.com/emqx/lc.git", {tag, "0.3.2"}}} , {redbug, "2.0.8"} , {covertool, {git, "https://github.com/zmstone/covertool", {tag, "2.0.4.1"}}} - , {gpb, "4.19.7"} + , {gpb, "4.19.9"} , {typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}} , {gun, {git, "https://github.com/emqx/gun", {tag, "1.3.9"}}} , {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.4.11"}}}