Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set port correctly in mssql connection string #731

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dlt/destinations/mssql/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def _get_odbc_driver(self) -> str:
def to_odbc_dsn(self) -> str:
params = {
"DRIVER": self.odbc_driver,
"SERVER": self.host,
"PORT": self.port,
"SERVER": f"{self.host},{self.port}",
"DATABASE": self.database,
"UID": self.username,
"PWD": self.password,
Expand Down
24 changes: 24 additions & 0 deletions tests/load/mssql/test_mssql_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from dlt.common.configuration import resolve_configuration

from dlt.destinations.mssql.configuration import MsSqlCredentials



def test_to_odbc_dsn() -> None:
creds = resolve_configuration(
MsSqlCredentials("mssql://test_user:[email protected]:12345/test_db?FOO=a&BAR=b")
)

dsn = creds.to_odbc_dsn()

result = {k: v for k, v in (param.split('=') for param in dsn.split(";"))}

assert result == {
'DRIVER': 'ODBC Driver 18 for SQL Server',

Choose a reason for hiding this comment

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

Amazing that the fix came so quickly! :)
I haven't looked into the codebase yet, so maybe my question is misunderstood;
Would this test fail for a developer who only have driver 17 installed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, that's true it would fail.
The test should specify the driver or ignore it in the assert.

'SERVER': 'sql.example.com,12345',
'DATABASE': 'test_db',
'UID': 'test_user',
'PWD': 'test_password',
'FOO': 'a',
'BAR': 'b'
}
8 changes: 6 additions & 2 deletions tests/load/pipeline/test_arrow_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def some_data():
assert some_table_columns["time"]["data_type"] == "time"

qual_name = pipeline.sql_client().make_qualified_table_name("some_data")
rows = [list(row) for row in select_data(pipeline, f"SELECT * FROM {qual_name} ORDER BY 1")]
rows = [list(row) for row in select_data(pipeline, f"SELECT * FROM {qual_name}")]

for row in rows:
for i in range(len(row)):
Expand All @@ -66,7 +66,7 @@ def some_data():
if isinstance(row[i], datetime):
row[i] = pendulum.instance(row[i])

expected = sorted([list(r.values()) for r in records], key=lambda x: x[0])
expected = sorted([list(r.values()) for r in records])

for row in expected:
for i in range(len(row)):
Expand All @@ -75,6 +75,10 @@ def some_data():

load_id = load_info.loads_ids[0]

# Sort rows by all columns except _dlt_id/_dlt_load_id for deterministic comparison
rows = sorted(rows, key=lambda row: row[:-2])
expected = sorted(expected)

for row, expected_row in zip(rows, expected):
# Compare without _dlt_id/_dlt_load_id columns
assert row[:-2] == expected_row
Expand Down
Loading