FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: set correct user agent for the dialect by IlyaFaer · Pull Request #116 · googleapis/python-spanner-sqlalchemy · GitHub

This repository was archived by the owner on May 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pkg_resources
import re

from sqlalchemy import types, ForeignKeyConstraint
Expand Down Expand Up @@ -433,9 +434,10 @@ def create_connect_args(self, url):
),
url.database,
)
dist = pkg_resources.get_distribution("sqlalchemy-spanner")
return (
[match.group("instance"), match.group("database"), match.group("project")],
{},
{"user_agent": dist.project_name + "/" + dist.version},
Comment thread
IlyaFaer marked this conversation as resolved.
)

@engine_to_connection
Expand Down
21 changes: 21 additions & 0 deletions test/test_suite.py
This file contains hidden or 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
Expand Up @@ -18,6 +18,7 @@
import decimal
import operator
import os
import pkg_resources
import pytest
from unittest import mock

Expand Down Expand Up @@ -1525,3 +1526,23 @@ def test_interleave_on_delete_cascade(self):
with mock.patch("google.cloud.spanner_dbapi.cursor.Cursor.execute") as execute:
client.create(self._engine)
execute.assert_called_once_with(EXP_QUERY, [])


class UserAgentTest(fixtures.TestBase):
"""Check that SQLAlchemy dialect uses correct user agent."""

def setUp(self):
self._engine = create_engine(
"spanner:///projects/appdev-soda-spanner-staging/instances/"
"sqlalchemy-dialect-test/databases/compliance-test"
)
self._metadata = MetaData(bind=self._engine)

def test_user_agent(self):
dist = pkg_resources.get_distribution("sqlalchemy-spanner")

with self._engine.connect() as connection:
assert (
connection.connection.instance._client._client_info.user_agent
== dist.project_name + "/" + dist.version
)
Comment thread
skuruppu marked this conversation as resolved.

Back | FazBrowse Home | New Git URL