Skip to content

Fix definitions import 18517 - #18518

Open
mkuratczyk wants to merge 2 commits into
mainfrom
fix-definitions-import-18517
Open

mkuratczyk wants to merge 2 commits into
mainfrom
fix-definitions-import-18517

Conversation

@mkuratczyk

Copy link
Copy Markdown
Contributor

Importing definitions exported for a single virtual host via POST /api/definitions
crashed the HTTP API handler instead of returning a 400. The check for queues, exchanges
and bindings without a virtual host threw outside of the try in
rabbit_definitions:apply_defs/3. It now returns {error, <<"invalid_definitions_file">>}.

While at it, this fixes how skip_if_unchanged handles a failed import. The content hash
was stored even when the import failed, so a retry with the same definitions was skipped
and reported success. Now the hash is stored only after a successful import. This covers
imports via the CLI, cluster-wide and for a single virtual host, and imports at boot from
a local file, a directory or an HTTPS source.

Note that at boot, an import error with skip_if_unchanged enabled now stops the node,
the same as it already does without skip_if_unchanged. Previously the error was ignored
and the hash was stored.

Fixes #18517

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The changed filesystem and HTTPS loader failure paths lack regression coverage confirming that failed resource imports preserve stored hashes and still fail on identical retries when skip_if_unchanged is enabled.

2 open issues
What changed in this PR

This PR corrects RabbitMQ’s definitions-import error handling, addressing #18517 and preventing failed imports from being skipped on retry.

Changes:

  • Returns HTTP 400 when vhost-scoped definitions are submitted to the cluster-wide endpoint
  • Stores content hashes only after successful imports and propagates boot-time import errors from filesystem and HTTPS sources
  • Adds regression tests for HTTP rejection and hash preservation after failed cluster-wide and vhost-specific imports
File Description
deps/​rabbitmq_management/​test/​rabbit_mgmt_http_SUITE.erl Checks the HTTP status and reason for rejected vhost-scoped definitions
deps/​rabbit/​test/​definition_import_SUITE.erl Checks that rejected and failed imports preserve stored hashes
deps/​rabbit/​src/​rabbit_definitions.erl Returns validation errors normally and stores hashes through success callbacks
deps/​rabbit/​src/​rabbit_definitions_import_local_filesystem.erl Propagates file and directory import failures instead of returning a hash
deps/​rabbit/​src/​rabbit_definitions_import_https.erl Propagates HTTPS import failures instead of returning a hash

Review effort: Balanced

_ = load_from_local_path(IsDir, Path),
Other
maybe
ok ?= load_from_local_path(IsDir, Path),
With `skip_if_unchanged` enabled, the content hash was stored even when
the import failed, so a retry of the same definitions was skipped and
reported success. This applies to imports via the CLI and to imports at
boot from a local file, a directory or an HTTPS source.

Note that at boot, an import error with `skip_if_unchanged` enabled now
stops the node, the same as it already does without `skip_if_unchanged`.
Previously the error was ignored and the hash was stored.

References #18517
The check for queues, exchanges and bindings without a virtual host
threw outside of the `try` in `rabbit_definitions:apply_defs/3`, so the
HTTP API handler crashed instead of returning a 400. Return the error
instead.

Fixes #18517
@mkuratczyk
mkuratczyk force-pushed the fix-definitions-import-18517 branch from 95d91f6 to 29dba53 Compare November 27, 2026 14:19
@mkuratczyk
mkuratczyk requested a balanced review from Copilot November 27, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cluster-wide definitions import of a vhost-scoped file returns 500 with no body

2 participants