-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fix make_connection_configuration for MSSQL (adding a driver) #113
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4a996d
add driver to MSSQL connection
TJaniF af870f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 041dc78
fix lint
TJaniF 1d0563a
adjust unit test
TJaniF a62a3c6
make mssql connection explicit add else statement
TJaniF a578e5b
adding default name for MS SQL server db because it does not accept t…
TJaniF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -239,6 +239,7 @@ def __init__( | |||||
def make_connection_configuration(self) -> Dict[str, str]: | ||||||
"""Builds connection strings based off existing Airflow connections. Only supports necessary extras.""" | ||||||
uri_string = "" | ||||||
driver = "" | ||||||
if not self.conn: | ||||||
raise ValueError(f"Connections does not exist in Airflow for conn_id: {self.conn_id}") | ||||||
self.schema = self.schema or self.conn.schema | ||||||
|
@@ -247,11 +248,19 @@ def make_connection_configuration(self) -> Dict[str, str]: | |||||
odbc_connector = "" | ||||||
if conn_type in ("redshift", "postgres"): | ||||||
odbc_connector = "postgresql+psycopg2" | ||||||
database_name = self.schema | ||||||
elif conn_type == "mysql": | ||||||
odbc_connector = "mysql" | ||||||
database_name = self.schema | ||||||
else: | ||||||
odbc_connector = "mssql+pyodbc" | ||||||
uri_string = f"{odbc_connector}://{self.conn.login}:{self.conn.password}@{self.conn.host}:{self.conn.port}/{self.schema}" # noqa | ||||||
ms_driver = self.conn.extra_dejson.get("driver") or "ODBC Driver 17 for SQL Server" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: not yet tested myself, but I think the following should work 🤔
Suggested change
|
||||||
driver = f"?driver={ms_driver}" | ||||||
database_name = self.conn.schema | ||||||
uri_string = ( | ||||||
f"{odbc_connector}://{self.conn.login}:{self.conn.password}@" | ||||||
f"{self.conn.host}:{self.conn.port}/{database_name}{driver}" | ||||||
) | ||||||
elif conn_type == "snowflake": | ||||||
try: | ||||||
return self.build_snowflake_connection_config_from_hook() | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will
conn_type = "mssql"
or something similar be passed to this method? If so could we please try something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Lee-W, thank you for your review!
Yes,
conn_type == "mssql"
will be passed in. I adjusted the code with your suggestion. I might actually add something about odbc connection types in a second PR, but I will have to test that first :)