Skip to content

Commit 9c4cbf2

Browse files
bas0Nmergify[bot]
authored andcommitted
Fix empty state field in /api/deprecated-features/used endpoint
The /api/deprecated-features/used endpoint was returning an empty state field in the JSON response. This was a regression introduced in #14229, which added the state field to show whether deprecated features are permitted or denied. The issue was that rabbit_depr_ff_extra:cli_info0/1 always tried to extract the state field with a default empty string, even when rabbit_deprecated_features:list(used) doesn't include a state field (unlike list(all) which does). This commit fixes the issue by only including the state field when it exists in the feature properties, using maps:find/2 and maps:merge/2 to conditionally add it. The fix ensures that: - /api/deprecated-features returns state field with valid values - /api/deprecated-features/used omits the state field entirely Tests are updated to verify this behavior. GitHub issue: #14340 (cherry picked from commit d2a3a60)
1 parent b821635 commit 9c4cbf2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

deps/rabbit/src/rabbit_depr_ff_extra.erl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ cli_info0(DeprecatedFeature) ->
5858

5959
App = maps:get(provided_by, FeatureProps),
6060
DeprecationPhase = maps:get(deprecation_phase, FeatureProps, ""),
61-
State = maps:get(state, FeatureProps, ""),
6261
Desc = maps:get(desc, FeatureProps, ""),
6362
DocUrl = maps:get(doc_url, FeatureProps, ""),
64-
Info = #{name => FeatureName,
65-
desc => unicode:characters_to_binary(Desc),
66-
deprecation_phase => DeprecationPhase,
67-
state => State,
68-
doc_url => unicode:characters_to_binary(DocUrl),
69-
provided_by => App},
63+
BaseInfo = #{name => FeatureName,
64+
desc => unicode:characters_to_binary(Desc),
65+
deprecation_phase => DeprecationPhase,
66+
doc_url => unicode:characters_to_binary(DocUrl),
67+
provided_by => App},
68+
Info = maps:merge(BaseInfo,
69+
case maps:find(state, FeatureProps) of
70+
{ok, State} -> #{state => State};
71+
error -> #{}
72+
end),
7073
[Info | Acc]
7174
end, [], lists:sort(maps:keys(DeprecatedFeature))).

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,7 +4228,9 @@ list_deprecated_features_test(Config) ->
42284228
?assertEqual(<<"permitted_by_default">>, maps:get(deprecation_phase, Feature)),
42294229
?assertEqual(atom_to_binary(?MODULE), maps:get(provided_by, Feature)),
42304230
?assertEqual(list_to_binary(Desc), maps:get(desc, Feature)),
4231-
?assertEqual(list_to_binary(DocUrl), maps:get(doc_url, Feature)).
4231+
?assertEqual(list_to_binary(DocUrl), maps:get(doc_url, Feature)),
4232+
?assert(maps:is_key(state, Feature)),
4233+
?assert(lists:member(maps:get(state, Feature), [<<"permitted">>, <<"denied">>])).
42324234

42334235
list_used_deprecated_features_test(Config) ->
42344236
Desc = "This is a deprecated feature in use",
@@ -4249,7 +4251,8 @@ list_used_deprecated_features_test(Config) ->
42494251
?assertEqual(<<"removed">>, maps:get(deprecation_phase, Feature)),
42504252
?assertEqual(atom_to_binary(?MODULE), maps:get(provided_by, Feature)),
42514253
?assertEqual(list_to_binary(Desc), maps:get(desc, Feature)),
4252-
?assertEqual(list_to_binary(DocUrl), maps:get(doc_url, Feature)).
4254+
?assertEqual(list_to_binary(DocUrl), maps:get(doc_url, Feature)),
4255+
?assertNot(maps:is_key(state, Feature)).
42534256

42544257
cluster_and_node_tags_test(Config) ->
42554258
Overview = http_get(Config, "/overview"),

0 commit comments

Comments
 (0)