Skip to content

fix(mongodb): don't add a slash after the first host in as_uri() - #2736

Open
LuisFigueroaG wants to merge 2 commits into
celery:mainfrom
LuisFigueroaG:fix/mongodb-as-uri-multiple-hosts
Open

LuisFigueroaG wants to merge 2 commits into
celery:mainfrom
LuisFigueroaG:fix/mongodb-as-uri-multiple-hosts

Conversation

@LuisFigueroaG

Copy link
Copy Markdown
Contributor

With more than one host in the broker URL, Transport.as_uri() sanitizes the first host on its own, and as_url() appends an empty path to it. So mongodb://user:pass@h1:27017,h2:27017/db?replicaSet=rs0 was displayed as mongodb://user:**@h1:27017/,h2:27017/db?replicaSet=rs0, for example in the Celery worker banner. The mask argument was also ignored, so as_uri(mask=...) always used **.

This strips the extra slash and passes mask through. Added tests for single-host, replica-set and no-credentials URLs, and for a custom mask.

Backward compatibility: this only affects the displayed, sanitized string. include_password=True still returns the URL unchanged, and connecting (_parse_uri) isn't touched. Single-host URLs give the same output as before unless a custom mask is passed.

With more than one host in the URL, as_uri() sanitized the first host on
its own, and as_url() appends an empty path to it, so
mongodb://user:pass@h1,h2/db came out as mongodb://user:**@h1/,h2/db.
Strip that slash, and pass the mask through instead of always using
the default one.
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.14%. Comparing base (4a8f695) to head (bfb70ac).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2736      +/-   ##
==========================================
+ Coverage   85.11%   85.14%   +0.02%     
==========================================
  Files          80       80              
  Lines       11357    11358       +1     
  Branches     1362     1362              
==========================================
+ Hits         9667     9671       +4     
+ Misses       1470     1468       -2     
+ Partials      220      219       -1     

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

@auvipy auvipy added this to the 5.7.0 milestone Oct 10, 2026
@auvipy
auvipy self-requested a review October 10, 2026 08:43
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.

2 participants