tortoise / tortoise/tortoise-orm
"Port is not an integer" when init connection
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
When init a connection , throws tortoise.exceptions.ConfigurationError: Port is not an integer exception.
I guess maybe it caused by the password charaters.
To Reproduce
Steps to reproduce the behavior, preferaby a small code snippet.
from tortoise import Tortoise, run_async
async def init():
# Here we create a SQLite DB using file "db.sqlite3"
# also specify the app name of "models"
# which contain models from "app.models"
await Tortoise.init(
db_url='mysql://root:1233onDB57#2020@myhost.com:33060/cs_app',
modules={'models': ['common.models']}
)
# Generate the schema
await Tortoise.generate_schemas()
# run_async is a helper function to run simple async Tortoise scripts.
run_async(init())
The error message:
Traceback (most recent call last):
File "/Users/maxwen/.conda/envs/csvw-spider/lib/python3.8/site-packages/tortoise/backends/base/config_generator.py", line 98, in expand_db_url
if vmap.get("port") and url.port:
File "/Users/maxwen/.conda/envs/csvw-spider/lib/python3.8/urllib/parse.py", line 177, in port
raise ValueError(message) from None
ValueError: Port could not be cast to integer value as '1233onDB57'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/xxx/Projects/python/csvw-spider/webapi/test.py", line 19, in <module>
run_async(init())
File "/Users/xxx/.conda/envs/csvw-spider/lib/python3.8/site-packages/tortoise/__init__.py", line 707, in run_async
loop.run_until_complete(coro)
File "/Users/xxx/.conda/envs/csvw-spider/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "/Users/xxx/Projects/python/csvw-spider/webapi/test.py", line 10, in init
await Tortoise.init(
File "/Users/xxx/.conda/envs/csvw-spider/lib/python3.8/site-packages/tortoise/__init__.py", line 558, in init
config = generate_config(db_url, modules)
File "/Users/xxx/.conda/envs/csvw-spider/lib/python3.8/site-packages/tortoise/backends/base/config_generator.py", line 125, in generate_config
"connections": {_connection_label: expand_db_url(db_url, testing)},
File "/Users/xxx/.conda/envs/csvw-spider/lib/python3.8/site-packages/tortoise/backends/base/config_generator.py", line 101, in expand_db_url
raise ConfigurationError("Port is not an integer")
tortoise.exceptions.ConfigurationError: Port is not an integer
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tortoise/backends/base/config_generator.py, especially expand_db_url(), and reproduce the shown MySQL connection URL. Trace how urllib.parse handles the URL and verify the resulting configuration does not raise the reported ConfigurationError; add or update a focused regression test if the repository contains relevant configuration tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100