Describe the bug
If we use init_beanie() to instantiate mongo client with connection_string and connect to a replica set, using port definitions like :27017 breaks the parser.
To Reproduce
% python -m asyncio
asyncio REPL 3.10.2 (main, Mar 15 2022, 15:34:56) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from beanie import init_beanie
>>> await init_beanie(connection_string='mongodb://192.168.0.1:27017,192.168.0.2:27017/test?replicaSet=test-rs&readPreference=primaryPreferred', document_models=[]) Traceback (most recent call last):
File "/home/vaizki/dev/admin_api/venv/lib/python3.10/site-packages/yarl/_url.py", line 166, in __new__
port = val.port
File "/usr/local/lib/python3.10/urllib/parse.py", line 178, in port
raise ValueError(message) from None
ValueError: Port could not be cast to integer value as '27017,192.168.0.2:27017'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 446, in result
return self.__get_result()
File "/usr/local/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
raise self._exception
File "<console>", line 1, in <module>
File "/home/vaizki/dev/admin_api/venv/lib/python3.10/site-packages/beanie/odm/utils/init.py", line 459, in init_beanie
await Initializer(
File "/home/vaizki/dev/admin_api/venv/lib/python3.10/site-packages/beanie/odm/utils/init.py", line 67, in __init__
URL(connection_string).path[1:]
File "/home/vaizki/dev/admin_api/venv/lib/python3.10/site-packages/yarl/_url.py", line 168, in __new__
raise ValueError(
ValueError: Invalid URL: port can't be converted to integer
Describe the bug If we use
init_beanie()
to instantiate mongo client withconnection_string
and connect to a replica set, using port definitions like:27017
breaks the parser.To Reproduce
Expected behavior Ports to be parsed host-by-host