Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit b5f977e

Browse files
author
Ilya Gurov
authored
feat: set a separate user agent for the DB API (#566)
* feat: set a separate user agent for the DB API * fix test error * fix the test
1 parent c7138ad commit b5f977e

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

google/cloud/spanner_dbapi/version.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pkg_resources
1516
import platform
1617

1718
PY_VERSION = platform.python_version()
18-
VERSION = "2.2.0a1"
19-
DEFAULT_USER_AGENT = "django_spanner/" + VERSION
19+
VERSION = pkg_resources.get_distribution("google-cloud-spanner").version
20+
DEFAULT_USER_AGENT = "dbapi/" + VERSION

tests/system/test_dbapi.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
import hashlib
1616
import pickle
17+
import pkg_resources
1718

1819
import pytest
1920

2021
from google.cloud import spanner_v1
21-
from google.cloud.spanner_dbapi.connection import Connection
22+
from google.cloud.spanner_dbapi.connection import connect, Connection
2223
from . import _helpers
2324

2425
DATABASE_NAME = "dbapi-txn"
@@ -357,3 +358,12 @@ def test_ping(shared_instance, dbapi_database):
357358
conn = Connection(shared_instance, dbapi_database)
358359
conn.validate()
359360
conn.close()
361+
362+
363+
def test_user_agent(shared_instance, dbapi_database):
364+
"""Check that DB API uses an appropriate user agent."""
365+
conn = connect(shared_instance.name, dbapi_database.name)
366+
assert (
367+
conn.instance._client._client_info.user_agent
368+
== "dbapi/" + pkg_resources.get_distribution("google-cloud-spanner").version
369+
)

0 commit comments

Comments
 (0)