Datastore: Add support for 'TransactionOptions'#4357
Datastore: Add support for 'TransactionOptions'#4357chemelnucfin merged 1 commit intogoogleapis:masterfrom
Conversation
|
hold on a second. I am still missing a couple comments. |
cee00af to
1b88972
Compare
dhermes
left a comment
There was a problem hiding this comment.
@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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| _status = None | ||
|
|
||
| def __init__(self, client): | ||
| def __init__(self, client, options=None): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| :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.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
|
|
||
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| def _make_datastore_api(*keys, **kwargs): | ||
| commit_method = mock.Mock( | ||
| return_value=_make_commit_response(*keys), spec=[]) | ||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
I mean, wouldn't it be good to have one here to make sure it doesn't reach
the network (like it is doing what it should do)?
…On Tue, Nov 28, 2017 at 2:09 PM, Danny Hermes ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In datastore/tests/system/test_system.py
<#4357 (comment)>
:
> @@ -442,6 +443,25 @@ def test_transaction_via_with_statement(self):
self.case_entities_to_delete.append(retrieved_entity)
self.assertEqual(retrieved_entity, entity)
+ def test_readonly_put(self):
The test above it (test_transaction_via_with_statement) actually talks to
the network.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4357 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADzDDArMkzdDy7R-dwVPKOnOJ5P1KfCrks5s7ISrgaJpZM4QV6hc>
.
|
|
No, we can test that code path with a unit test. |
0ecd530 to
c92036a
Compare
| lookup_response = datastore_api.lookup( | ||
| project, | ||
| key_pbs, | ||
| keys=key_pbs, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| """Proxy to :class:`google.cloud.datastore.batch.Batch`.""" | ||
| return Batch(self) | ||
|
|
||
| def read_only_transaction(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| else: | ||
| options = TransactionOptions( | ||
| read_only=TransactionOptions.ReadOnly()) | ||
| self.options = options |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| self._id = None | ||
|
|
||
| def put(self, entity): | ||
| """Ensures the transaction is not marked readonly and calls Batch.put |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| begin.assert_called_once() | ||
| self.assertEqual(begin.call_count, 1) | ||
|
|
||
| def test_previous_tid(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| with self.assertRaises(RuntimeError): | ||
| xact.put(entity) | ||
|
|
||
| def test_put_read_write(self): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
This comment was marked as spam.
Sorry, something went wrong.
c92036a to
8128847
Compare
008eea6 to
619b42c
Compare
|
@tseaver PTAL, thanks. |
dhermes
left a comment
There was a problem hiding this comment.
LGTM other than my last comment
datastore/tests/unit/test_client.py
Outdated
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| def transaction(self, **kwargs): | ||
| """Proxy to :class:`google.cloud.datastore.transaction.Transaction`. | ||
|
|
||
| :type kwargs: dict |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ee82c35 to
a7e2b2b
Compare
a7e2b2b to
7f1155e
Compare
|
@tseaver any comments? |
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.