Skip to content

Fix empty list handling in command map normalization#271

Merged
comtihon merged 1 commit into
comtihon:masterfrom
haoxianhan:fix/find-and-modify-empty-list-normalization
Mar 13, 2026
Merged

Fix empty list handling in command map normalization#271
comtihon merged 1 commit into
comtihon:masterfrom
haoxianhan:fix/find-and-modify-empty-list-normalization

Conversation

@haoxianhan

Copy link
Copy Markdown
Contributor

Summary

Fix command map normalization so empty lists stay [] instead of becoming #{}.

Minimal Reproduction

Using mc_worker_api interface:

{ok, Conn} = mc_worker_api:connect([
  {database, <<"test">>},
  {host, "127.0.0.1"},
  {port, 27027},
  {use_legacy_protocol, false}
]).

Collection = <<"tuple_norm_fix_repro">>.

{{true, _}, _} = mc_worker_api:insert(Conn, Collection, #{
  <<"_id">> => 1,
  <<"test_0">> => 0,
  <<"test_1">> => <<"hello">>,
  <<"test_3">> => []
}).

{true, Res} = mc_worker_api:command(Conn, #{
  <<"findAndModify">> => Collection,
  <<"query">> => #{<<"test_0">> => 0},
  <<"update">> => #{
    <<"$set">> => #{
      <<"test_1">> => <<"hello111">>,
      <<"test_3">> => []
    }
  },
  <<"new">> => true
}).

Before this fix, maps:get(<<"value">>, Res) contained:

#{<<"_id">> => 1,
  <<"test_0">> => 0,
  <<"test_1">> => <<"hello111">>,
  <<"test_3">> => #{}}

After this fix, the same call returns:

#{<<"_id">> => 1,
  <<"test_0">> => 0,
  <<"test_1">> => <<"hello111">>,
  <<"test_3">> => []}

`findAndModify` is one concrete reproduction path; the root cause is in shared
command map normalization.

@comtihon comtihon merged commit 3566863 into comtihon:master Mar 13, 2026
13 checks passed
@comtihon

Copy link
Copy Markdown
Owner

thank you!

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.

2 participants