Skip to content

Conversation

@chemelnucfin
Copy link
Contributor

@chemelnucfin chemelnucfin commented Nov 8, 2017

Changes reflecting review and Luke's autogen (please see #4348 for issues regarding his autogen). A manual fix has been included.

Closes #4335. This includes reviews and changes from there.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 8, 2017
@chemelnucfin chemelnucfin added the api: datastore Issues related to the Datastore API. label Nov 8, 2017
@chemelnucfin
Copy link
Contributor Author

hold on a second. I am still missing a couple comments.

@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch 3 times, most recently from cee00af to 1b88972 Compare November 8, 2017 22:46
Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chemelnucfin This PR does add partial support for TransactionOptions, but there is still much more to do to actually use the previous_transaction field "automatically" for users.

project_id,
keys,
read_options=None,
keys=None,

This comment was marked as spam.

This comment was marked as spam.

_status = None

def __init__(self, client):
def __init__(self, client, options=None):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

self.case_entities_to_delete.append(retrieved_entity)
self.assertEqual(retrieved_entity, entity)

def test_readonly_put(self):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

def test_readwrite_put(self):
entity = datastore.Entity(key=Config.CLIENT.key('Company', 'Google'))
options = types.TransactionOptions(
read_write=types.TransactionOptions.ReadWrite())

This comment was marked as spam.

:type client: :class:`google.cloud.datastore.client.Client`
:param client: the client used to connect to datastore.
:type options: `google.cloud.datastore.transaction.TransactionOptions`

This comment was marked as spam.



def _assert_num_mutations(test_case, mutation_pb_list, num_mutations):
test_case.assertEqual(len(mutation_pb_list), num_mutations)

This comment was marked as spam.

client = _Client(project, datastore_api=ds_api)
options = self._make_options(read_write=
self._make_options().ReadWrite(
previous_transaction=b'321'))

This comment was marked as spam.

ds_api = _make_datastore_api(xact_id=id_)
client = _Client(project, datastore_api=ds_api)
options = self._make_options(read_write=
self._make_options().ReadWrite(

This comment was marked as spam.

id_ = 943243
ds_api = _make_datastore_api(xact_id=id_)
client = _Client(project, datastore_api=ds_api)
options = self._make_options(read_only=self._make_options().ReadOnly())

This comment was marked as spam.

def _make_datastore_api(*keys, **kwargs):
commit_method = mock.Mock(
return_value=_make_commit_response(*keys), spec=[])

This comment was marked as spam.

@chemelnucfin
Copy link
Contributor Author

chemelnucfin commented Nov 28, 2017 via email

@dhermes
Copy link
Contributor

dhermes commented Nov 28, 2017

No, we can test that code path with a unit test.

@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch 8 times, most recently from 0ecd530 to c92036a Compare November 29, 2017 07:31
@chemelnucfin
Copy link
Contributor Author

chemelnucfin commented Nov 29, 2017

@dhermes @tseaver PTAL.

I will still need to think about how to retry the previous_transaction field though.

lookup_response = datastore_api.lookup(
project,
key_pbs,
keys=key_pbs,

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"""Proxy to :class:`google.cloud.datastore.batch.Batch`."""
return Batch(self)

def read_only_transaction(self):

This comment was marked as spam.

else:
options = TransactionOptions(
read_only=TransactionOptions.ReadOnly())
self.options = options

This comment was marked as spam.

def __init__(self, client, read_only=False):
super(Transaction, self).__init__(client)
self._id = None
if not read_only:

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

self._id = None

def put(self, entity):
"""Ensures the transaction is not marked readonly and calls Batch.put

This comment was marked as spam.

client = _Client(project, datastore_api=ds_api)
read_only = self._get_options_class().ReadOnly()
options = self._make_options(read_only=read_only)
xact = self._make_one(client, read_only=True)

This comment was marked as spam.

begin.assert_called_once()
self.assertEqual(begin.call_count, 1)

def test_previous_tid(self):

This comment was marked as spam.

with self.assertRaises(RuntimeError):
xact.put(entity)

def test_put_read_write(self):

This comment was marked as spam.

self.assertEqual(mutated_entity.key, entity.key.to_protobuf())


def _mutated_pb(test_case, mutation_pb_list, mutation_type):

This comment was marked as spam.

ds_api = _make_datastore_api(xact_id=id_)
client = _Client(project, datastore_api=ds_api)
options_klass = self._get_options_class()
options = self._make_options(read_only=options_klass.ReadOnly())

This comment was marked as spam.

@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch from c92036a to 8128847 Compare November 29, 2017 19:40
@tseaver
Copy link
Contributor

tseaver commented Dec 4, 2017

@chemelnucfin Lint failure.

@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch 3 times, most recently from 008eea6 to 619b42c Compare December 4, 2017 19:58
@chemelnucfin
Copy link
Contributor Author

@tseaver PTAL, thanks.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than my last comment

client = self._make_one(credentials=creds)
xact = client.transaction(read_only=True)
self.assertIsInstance(xact._options.read_only,
TransactionOptions.ReadOnly)

This comment was marked as spam.

self.assertIsInstance(xact._options.read_only,
TransactionOptions.ReadOnly)
self.assertEqual(xact._options.read_only,
TransactionOptions.ReadOnly())

This comment was marked as spam.

This comment was marked as spam.

def transaction(self, **kwargs):
"""Proxy to :class:`google.cloud.datastore.transaction.Transaction`.
:type kwargs: dict

This comment was marked as spam.

Copy link
Contributor

@dhermes dhermes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch from ee82c35 to a7e2b2b Compare December 6, 2017 19:06
@chemelnucfin chemelnucfin force-pushed the issue4278-transactionoption2 branch from a7e2b2b to 7f1155e Compare December 6, 2017 19:11
@chemelnucfin
Copy link
Contributor Author

@tseaver any comments?

@chemelnucfin chemelnucfin merged commit f4bdb33 into googleapis:master Dec 11, 2017
@chemelnucfin chemelnucfin deleted the issue4278-transactionoption2 branch December 11, 2017 17:51
parthea pushed a commit that referenced this pull request Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants