Skip to content

Fix hashing and equality consistency in RabbitMQ schemas#2791

Closed
RinZ27 wants to merge 1 commit intoag2ai:mainfrom
RinZ27:fix/rmq-schemas-hashing-consistency
Closed

Fix hashing and equality consistency in RabbitMQ schemas#2791
RinZ27 wants to merge 1 commit intoag2ai:mainfrom
RinZ27:fix/rmq-schemas-hashing-consistency

Conversation

@RinZ27
Copy link

@RinZ27 RinZ27 commented Mar 1, 2026

Description

Addressing the architectural inconsistency in RabbitMQ schemas where __eq__ and __hash__ were out of sync. This fix ensures that RabbitQueue, RabbitExchange, and Channel objects behave correctly when used in dictionaries or sets, which is critical for the RabbitDeclarer caching mechanism.

Previously, RabbitQueue and RabbitExchange inherited __eq__ from NameRequired (comparing only by name), while their __hash__ methods included multiple other attributes (like durable, auto_delete, etc.). This violation of the Python data model could lead to cache misses or incorrect object reuse in the declarer.

For the Channel class, identity-based hashing was used despite being a dataclass with value-based equality. This has been corrected to use value-based hashing for consistency.

Type of change

  • Bug fix (a non-breaking change that resolves an issue)

Checklist

  • My code adheres to the style guidelines of this project
  • I have conducted a self-review of my own code
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix
  • Both new and existing unit tests pass successfully on my local environment
  • I have included code examples to illustrate the modifications (tests added to tests/brokers/rabbit/test_schemas.py)

@RinZ27 RinZ27 requested a review from Lancetnik as a code owner March 1, 2026 13:34
@CLAassistant
Copy link

CLAassistant commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

@RinZ27 RinZ27 force-pushed the fix/rmq-schemas-hashing-consistency branch 4 times, most recently from 939c1ba to 61b9934 Compare March 1, 2026 23:47
and self.routing_key == value.routing_key
and self.durable == value.durable
and self.auto_delete == value.auto_delete
and self.robust == value.robust
Copy link
Member

Choose a reason for hiding this comment

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

robust is not required here

self.routing_key,
self.durable,
self.auto_delete,
self.robust,
Copy link
Member

Choose a reason for hiding this comment

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

and here

and self.durable == value.durable
and self.exclusive == value.exclusive
and self.auto_delete == value.auto_delete
and self.robust == value.robust
Copy link
Member

Choose a reason for hiding this comment

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

and here

self.durable,
self.exclusive,
self.auto_delete,
self.robust,
Copy link
Member

Choose a reason for hiding this comment

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

and here

Copy link
Member

Choose a reason for hiding this comment

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

Please, revert this file changes

Copy link
Member

Choose a reason for hiding this comment

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

And this one

@RinZ27 RinZ27 closed this Mar 3, 2026
@RinZ27 RinZ27 force-pushed the fix/rmq-schemas-hashing-consistency branch from 61b9934 to 39deb22 Compare March 3, 2026 14:16
@github-actions github-actions bot added dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code Confluent Issues related to `faststream.confluent` module AioKafka Issues related to `faststream.kafka` module NATS Issues related to `faststream.nats` module and NATS broker features Redis Issues related to `faststream.redis` module and Redis features Observability labels Mar 3, 2026
@RinZ27
Copy link
Author

RinZ27 commented Mar 3, 2026

@Lancetnik I'm very sorry for the mess in the previous push. My local environment was misconfigured, which caused an accidental push of thousands of unrelated files.

I have strictly cleaned up the branch now. It contains only the 3 relevant schema files with consistent hashing/equality logic and the removal of the robust parameter as you requested.

Could you please reopen the PR? I promise it's clean and focused now. Thank you for your patience!

@Lancetnik
Copy link
Member

@RinZ27 sorry, I can't reopen it - the button is disabled. But, you can open an another one, it's not a problem

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

Labels

AioKafka Issues related to `faststream.kafka` module Confluent Issues related to `faststream.confluent` module dependencies Pull requests that update a dependency file github_actions Pull requests that update GitHub Actions code NATS Issues related to `faststream.nats` module and NATS broker features Observability Redis Issues related to `faststream.redis` module and Redis features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants