diff --git a/src/khepri.erl b/src/khepri.erl index 07892a07..1e76b9e5 100644 --- a/src/khepri.erl +++ b/src/khepri.erl @@ -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. %% @@ -372,6 +366,26 @@ %% returned as well. %% +-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. %% diff --git a/src/khepri_tree.erl b/src/khepri_tree.erl index f97cef57..3371a542 100644 --- a/src/khepri_tree.erl +++ b/src/khepri_tree.erl @@ -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) -> diff --git a/test/queries.erl b/test/queries.erl index ed84b82b..ab878799 100644 --- a/test/queries.erl +++ b/test/queries.erl @@ -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).