Skip to content
This repository was archived by the owner on May 6, 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

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 google/cloud/ndb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from google.cloud import environment_vars
from google.cloud import _helpers
from google.cloud import client as google_client
from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.datastore_v1.services.datastore.transports import (
grpc as datastore_grpc,
)
Expand Down Expand Up @@ -106,7 +105,7 @@ def __init__(
credentials=None,
client_options=None,
*,
database: str = DEFAULT_DATABASE
database: str = ""
):
self.namespace = namespace
self.host = os.environ.get(environment_vars.GCD_HOST, DATASTORE_API_HOST)
Expand Down
9 changes: 4 additions & 5 deletions google/cloud/ndb/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ class Key(object):

from unittest import mock
from google.cloud.ndb import context as context_module
from google.cloud.datastore.constants import DEFAULT_DATABASE
client = mock.Mock(
project="testing",
database=DEFAULT_DATABASE,
database="",
namespace=None,
stub=mock.Mock(spec=()),
spec=("project", "database", "namespace", "stub"),
Expand Down Expand Up @@ -465,7 +464,7 @@ def __setstate__(self, state):
_clean_flat_path(flat)
project = _project_from_app(kwargs["app"])

database = google.cloud.datastore.constants.DEFAULT_DATABASE
database = ""
if "database" in kwargs:
database = kwargs["database"]

Expand Down Expand Up @@ -600,7 +599,7 @@ def database(self):
>>> key.database()
'mydb'
"""
db = self._key.database or google.cloud.datastore.constants.DEFAULT_DATABASE
db = self._key.database or ""
return db

def id(self):
Expand Down Expand Up @@ -1454,7 +1453,7 @@ def _parse_from_args(
namespace = None

if database is None:
database = google.cloud.datastore.constants.DEFAULT_DATABASE
database = ""

return google.cloud.datastore.Key(
*flat,
Expand Down
3 changes: 1 addition & 2 deletions google/cloud/ndb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

from unittest import mock
from google.cloud import ndb
from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.ndb import context as context_module

client = mock.Mock(
project="testing",
database=DEFAULT_DATABASE,
database="",
namespace=None,
stub=mock.Mock(spec=()),
spec=("project", "namespace", "database", "stub"),
Expand Down
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import os

from google.cloud import environment_vars
from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.ndb import context as context_module
from google.cloud.ndb import _eventloop
from google.cloud.ndb import global_cache as global_cache_module
Expand Down Expand Up @@ -89,7 +88,7 @@ def context_factory():
def context(**kwargs):
client = mock.Mock(
project="testing",
database=DEFAULT_DATABASE,
database="",
namespace=None,
spec=("project", "database", "namespace"),
stub=mock.Mock(spec=()),
Expand Down
3 changes: 1 addition & 2 deletions tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from google.cloud import datastore
from google.cloud import ndb
from google.cloud.datastore.constants import DEFAULT_DATABASE

from google.cloud.ndb import global_cache as global_cache_module

Expand Down Expand Up @@ -133,7 +132,7 @@ def database():


def _get_database():
db = DEFAULT_DATABASE
db = ""
if TEST_DATABASE is not None:
db = TEST_DATABASE
return db
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/test__datastore_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from google.cloud.datastore import entity
from google.cloud.datastore import helpers
from google.cloud.datastore import key as ds_key_module
from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.datastore_v1.types import datastore as datastore_pb2
from google.cloud.datastore_v1.types import entity as entity_pb2
from google.cloud.ndb import _batch
Expand Down Expand Up @@ -1247,7 +1246,7 @@ def test_wo_transaction(stub, datastore_pb2):

datastore_pb2.CommitRequest.assert_called_once_with(
project_id="testing",
database_id=DEFAULT_DATABASE,
database_id="",
mode=datastore_pb2.CommitRequest.Mode.NON_TRANSACTIONAL,
mutations=mutations,
transaction=None,
Expand All @@ -1270,7 +1269,7 @@ def test_w_transaction(stub, datastore_pb2):

datastore_pb2.CommitRequest.assert_called_once_with(
project_id="testing",
database_id=DEFAULT_DATABASE,
database_id="",
mode=datastore_pb2.CommitRequest.Mode.TRANSACTIONAL,
mutations=mutations,
transaction=b"tx123",
Expand Down Expand Up @@ -1362,7 +1361,7 @@ def test__datastore_allocate_ids(stub, datastore_pb2):
assert _api._datastore_allocate_ids(keys).result() == "response"

datastore_pb2.AllocateIdsRequest.assert_called_once_with(
project_id="testing", database_id=DEFAULT_DATABASE, keys=keys
project_id="testing", database_id="", keys=keys
)

request = datastore_pb2.AllocateIdsRequest.return_value
Expand Down Expand Up @@ -1403,7 +1402,7 @@ def test_read_only(stub, datastore_pb2):
transaction_options = datastore_pb2.TransactionOptions.return_value
datastore_pb2.BeginTransactionRequest.assert_called_once_with(
project_id="testing",
database_id=DEFAULT_DATABASE,
database_id="",
transaction_options=transaction_options,
)

Expand All @@ -1428,7 +1427,7 @@ def test_read_write(stub, datastore_pb2):
transaction_options = datastore_pb2.TransactionOptions.return_value
datastore_pb2.BeginTransactionRequest.assert_called_once_with(
project_id="testing",
database_id=DEFAULT_DATABASE,
database_id="",
transaction_options=transaction_options,
)

Expand Down Expand Up @@ -1460,7 +1459,7 @@ def test__datastore_rollback(stub, datastore_pb2):
assert _api._datastore_rollback(b"tx123").result() == "response"

datastore_pb2.RollbackRequest.assert_called_once_with(
project_id="testing", database_id=DEFAULT_DATABASE, transaction=b"tx123"
project_id="testing", database_id="", transaction=b"tx123"
)

request = datastore_pb2.RollbackRequest.return_value
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import google.cloud.datastore
import pytest

from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.ndb import exceptions
from google.cloud.ndb import key as key_module
from google.cloud.ndb import model
Expand Down Expand Up @@ -233,12 +232,12 @@ def test_constructor_with_project_and_app():
@staticmethod
@pytest.mark.usefixtures("in_context")
def test_constructor_with_default_database():
key = key_module.Key("Kind", 1337, database=DEFAULT_DATABASE)
key = key_module.Key("Kind", 1337, database="")

assert key._key == google.cloud.datastore.Key(
"Kind", 1337, project="testing", database=DEFAULT_DATABASE
"Kind", 1337, project="testing", database=""
)
assert key.database() == DEFAULT_DATABASE
assert key.database() == ""

@staticmethod
@pytest.mark.usefixtures("in_context")
Expand Down Expand Up @@ -520,9 +519,7 @@ def test_pickling():
@staticmethod
@pytest.mark.usefixtures("in_context")
def test_pickling_with_default_database():
key = key_module.Key(
"a", "b", app="c", namespace="d", database=DEFAULT_DATABASE
)
key = key_module.Key("a", "b", app="c", namespace="d", database="")
pickled = pickle.dumps(key)
unpickled = pickle.loads(pickled)
assert key == unpickled
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from google.cloud.datastore import entity as entity_module
from google.cloud.datastore import key as ds_key_module
from google.cloud.datastore import helpers
from google.cloud.datastore.constants import DEFAULT_DATABASE
from google.cloud.datastore_v1 import types as ds_types
from google.cloud.datastore_v1.types import entity as entity_pb2
import pytest
Expand Down Expand Up @@ -2624,7 +2623,7 @@ class KeyPropTestModel(model.Model):
k = model.KeyProperty()

kptm1 = KeyPropTestModel(k=key_module.Key("k", 1))
kptm2 = KeyPropTestModel(k=key_module.Key("k", 1, database=DEFAULT_DATABASE))
kptm2 = KeyPropTestModel(k=key_module.Key("k", 1, database=""))
assert kptm1 == kptm2


Expand Down Expand Up @@ -6125,7 +6124,7 @@ def test_not_entity_proto_raises_error():
def test_with_key():
m = model.Model()
pb = _legacy_entity_pb.EntityProto()
key = key_module.Key("a", "b", app="c", database=DEFAULT_DATABASE, namespace="")
key = key_module.Key("a", "b", app="c", database="", namespace="")
ent = m._from_pb(pb, key=key)
assert ent.key == key

Expand Down
Loading