Fix empty state field in /api/deprecated-features/used endpoint #15042
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Tests are updated to verify this behavior.
GitHub issue: #14340
Proposed Changes
This PR fixes a regression introduced in #14229 where the
/api/deprecated-features/usedendpoint was returning an emptystatefield in the JSON response.The Problem:
statefield to show whether deprecated features arepermittedordeniedrabbit_deprecated_features:list(all)function includes thestatefield, butlist(used)does notrabbit_depr_ff_extra:cli_info0/1always tried to extract thestatefield with a default empty string, resulting in"state": ""in the response for the/usedendpointThe Solution:
rabbit_depr_ff_extra:cli_info0/1to conditionally include thestatefield only when it exists in the feature propertiesmaps:find/2andmaps:merge/2for a more idiomatic Erlang approach/api/deprecated-featuresincludes thestatefield with valid values (permittedordenied)/api/deprecated-features/usedomits thestatefield entirelyThis ensures the API response matches the expected behavior: the
statefield is either set correctly or omitted, never empty.Types of Changes
What types of changes does your code introduce to this project?
Put an
xin the boxes that applyChecklist
Put an
xin the boxes that apply.You can also fill these out after creating the PR.
This is simply a reminder of what we are going to look for before merging your code.
CONTRIBUTING.mddocumentFurther Comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution
you did and what alternatives you considered, etc.