Skip to content

Commit

Permalink
Merge pull request #308 from rabbitmq/ignore-unknown-props_to_return
Browse files Browse the repository at this point in the history
khepri_tree: Ignore unknown props to return
  • Loading branch information
dumbbell authored Dec 11, 2024
2 parents 6f88694 + 257cf32 commit 39a97d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,8 @@
%% set, `condition' takes precedence and `favor' is ignored.

-type tree_options() :: #{expect_specific_node => boolean(),
props_to_return => [payload_version |
child_list_version |
child_list_length |
child_names |
payload |
has_payload |
raw_payload |
delete_reason],
props_to_return => [known_prop_to_return() |
unknown_prop_to_return()],
include_root_props => boolean()}.
%% Options used during tree traversal.
%%
Expand All @@ -372,6 +366,26 @@
%% returned as well.</li>
%% </ul>

-type known_prop_to_return() :: payload_version |
child_list_version |
child_list_length |
child_names |
payload |
has_payload |
raw_payload |
delete_reason.
%% Name of a known property to return.
%%
%% To be used in {@link khepri:tree_options()} `props_to_return' list.

-type unknown_prop_to_return() :: atom().
%% Name of a property unknown to this version of Khepri.
%%
%% This can happen when a query is emitted by a newer version of Khepri that
%% added new properties to return.
%%
%% Can be seen in {@link khepri:tree_options()} `props_to_return' list.

-type put_options() :: #{keep_while => khepri_condition:keep_while()}.
%% Options specific to updates.
%%
Expand Down
4 changes: 3 additions & 1 deletion src/khepri_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ gather_node_props(#node{props = #{payload_version := PVersion,
end;
(raw_payload, Acc) ->
Acc#{raw_payload => Payload};
(delete_reason, Acc) ->
(_Unknown, Acc) ->
%% We ignore props we don't know about. It might be a new one in
%% a future version of the machine.
Acc
end, #{}, WantedProps);
gather_node_props(#node{}, _Options) ->
Expand Down
14 changes: 14 additions & 0 deletions test/queries.erl
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,17 @@ include_child_names_in_query_response_test() ->
child_list_version => 2,
child_names => [bar, quux]}}},
Ret).

use_an_unknown_prop_to_return_test() ->
Commands = [#put{path = [foo],
payload = khepri_payload:data(value)}],
S0 = khepri_machine:init(?MACH_PARAMS(Commands)),
Tree = khepri_machine:get_tree(S0),
Ret = khepri_tree:find_matching_nodes(
Tree, [foo],
#{props_to_return => [payload,
future_prop_name]}),

?assertEqual(
{ok, #{[foo] => #{data => value}}},
Ret).

0 comments on commit 39a97d7

Please sign in to comment.