Skip to content

Commit

Permalink
Fix SQL server instance names
Browse files Browse the repository at this point in the history
  • Loading branch information
olsen232 committed Sep 3, 2024
1 parent ddd03ae commit 9be521b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where
## 0.15.3 (UNRELEASED)

- Replaces minimal patches with delta-filters - a more general-purpose way of filtering parts (inserts, updates, deletes) of JSON diffs when not all parts are required. [#998](https://github.com/koordinates/kart/pull/998)
- Remove automatic resolution of `localhost` before calling MSSQL driver. Fixes SQL Server instance names issue. [#999](https://github.com/koordinates/kart/issues/999)

## 0.15.2

Expand Down
7 changes: 0 additions & 7 deletions kart/sqlalchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ def _pool_class(cls):
# But this fix is simpler for now: disable the pool during testing.
return NullPool if "PYTEST_CURRENT_TEST" in os.environ else None

@classmethod
def _replace_localhost_with_ip(cls, url_netloc):
def _get_localhost_ip(*args, **kwargs):
return socket.gethostbyname("localhost")

return re.sub(r"\blocalhost\b", _get_localhost_ip, url_netloc)

@classmethod
def _append_query_to_url(cls, uri, new_query_dict):
url = urlsplit(uri)
Expand Down
5 changes: 1 addition & 4 deletions kart/sqlalchemy/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def create_engine(cls, msurl):
{"driver": cls.get_sqlserver_driver(), "Application Name": "kart"},
)

# SQL Server driver prefers 127.0.0.1 or similar to localhost.
url_netloc = cls._replace_localhost_with_ip(url.netloc)

msurl = urlunsplit([cls.INTERNAL_SCHEME, url_netloc, url.path, url_query, ""])
msurl = urlunsplit([cls.INTERNAL_SCHEME, url.netloc, url.path, url_query, ""])

engine = sqlalchemy.create_engine(msurl, poolclass=cls._pool_class())
return engine
Expand Down

0 comments on commit 9be521b

Please sign in to comment.