Skip to content

Implement missing _delete() method of filesystem.Channel#2470

Open
WojciechMigda wants to merge 19 commits intocelery:mainfrom
WojciechMigda:transport-filesystem-channel-delete
Open

Implement missing _delete() method of filesystem.Channel#2470
WojciechMigda wants to merge 19 commits intocelery:mainfrom
WojciechMigda:transport-filesystem-channel-delete

Conversation

@WojciechMigda
Copy link
Copy Markdown

As of now, Channel class of filesystem transport does not have a _delete method. It prevents queues from being removed from an associated exchange. This PR intents to remedy that.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements the missing filesystem transport Channel._delete() behavior so that deleting a queue also removes its binding from the exchange’s persisted routing table (control files), preventing bindings from leaking across test cases and runs.

Changes:

  • Add Channel._delete() to update control_folder/<exchange>.exchange when queues are deleted.
  • Expand filesystem transport unit tests to validate exchange-table updates after Queue.delete().
  • Isolate tests via per-test temporary control_folder and explicit cleanup of temp folders/bindings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
kombu/transport/filesystem.py Adds _delete() to remove bindings from the persisted exchange routing table file.
t/unit/transport/test_filesystem.py Adds assertions around binding-table contents and improves test isolation/cleanup for filesystem transport.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kombu/transport/filesystem.py Outdated
Comment thread kombu/transport/filesystem.py Outdated
Comment thread t/unit/transport/test_filesystem.py Outdated
Comment thread t/unit/transport/test_filesystem.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@WojciechMigda
Copy link
Copy Markdown
Author

I'll take care of this.

WojciechMigda and others added 4 commits March 1, 2026 22:07
Duplicated temporary folder removal code was extracted
to WithJanitorMixin class.

Safe queue deletion was taken care of by creating managed_consumer function,
decorated with contextlib.contextmanager.
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.42%. Comparing base (9022fcc) to head (bbf296e).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
kombu/transport/filesystem.py 76.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2470      +/-   ##
==========================================
- Coverage   82.44%   82.42%   -0.03%     
==========================================
  Files          79       79              
  Lines       10142    10167      +25     
  Branches     1165     1167       +2     
==========================================
+ Hits         8362     8380      +18     
- Misses       1579     1583       +4     
- Partials      201      204       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

would you mind improving the test coverage, Please?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread t/unit/transport/test_filesystem.py Outdated
Comment thread t/unit/transport/test_filesystem.py Outdated
Comment thread kombu/transport/filesystem.py Outdated
auvipy and others added 4 commits March 3, 2026 12:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@WojciechMigda
Copy link
Copy Markdown
Author

would you mind improving the test coverage, Please?

Sure thing.

@auvipy auvipy added this to the 5.7.0 milestone Mar 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 41 to +46
def setup_method(self):
self.channels = set()
self.channels: set[Channel] = set()
try:
data_folder_in = tempfile.mkdtemp()
data_folder_out = tempfile.mkdtemp()
self.data_folder_in = tempfile.mkdtemp()
self.data_folder_out = tempfile.mkdtemp()
self.control_folder = tempfile.mkdtemp()
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

Filesystem transport uses a class-level BrokerState (Transport.global_state) shared across tests. Since this setup now creates a fresh temporary control_folder each test and teardown removes it, stale bindings from prior tests can cause queue_bind to early-return (state.has_binding==True) and skip writing the exchange table into the new control_folder, breaking routing/hanging these tests. Consider clearing kombu.transport.filesystem.Transport.global_state in setup/teardown, or make exchange/queue names unique per test so bindings are re-declared for the new folders.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@WojciechMigda would you mind cross checking this, please?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There was an issue of shared global mutable state leaking between existing tests and part of the changes I introduced aimed at resolving this. Namely, exchange file contents from one test was not being torn down and subsequent test not only saw that but its code was written around it.

In my experience, the way to approach risks involved with shared mutable global state in tests is to put sufficient safeguards into proper test cleanup and not add more global mutable state (shared control folder). Here, as I understand it, as long as we clean up all queues associated with consumers (managed_consumer) we are safe in that respect.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

To satisfy LLM we could insert assertions which check that there are no stale bindings left when the test is completed. I am not sure though, if there is a public, or otherwise accessible API allowing us to do that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants