tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.38k stars 356 forks source link

Fix dsn for mssql named instances #1600

Open adi1 opened 2 months ago

adi1 commented 2 months ago

Description

Remove port from an mssql dsn when using named instances.

Motivation and Context

MSSQL named instances use dynamic port numbers. You can either connect directly to the port, or to the named instance. Providing a DB URL like mssql://user:pass@host\instance/db?driver=FreeTDS will result in a DSN which looks like DRIVER=FreeTDS;SERVER=host\instance,1433;UID=user;PWD=pass; because the default port is added. This fails to connect, because the instance is not listening on port 1443.

https://github.com/tortoise/tortoise-orm/issues/1566

How Has This Been Tested?

I have only tested locally with and without named instances.

Checklist:

abondar commented 1 month ago

Hello!

Please try to write test for it You can limit test to only mssql the same way we do it for postgres/mysql tests in tests/backends as example