Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

khepri_tree: Ignore unknown props to return #308

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
Loading