Skip to content

Commit

Permalink
Added missing operation_id to update_ddl method (#6737)
Browse files Browse the repository at this point in the history
  • Loading branch information
potiuk committed Dec 2, 2018
1 parent 1e8907b commit 9c2d2bd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
6 changes: 4 additions & 2 deletions spanner/google/cloud/spanner_v1/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def reload(self):
response = api.get_database_ddl(self.name, metadata=metadata)
self._ddl_statements = tuple(response.statements)

def update_ddl(self, ddl_statements):
def update_ddl(self, ddl_statements, operation_id=''):
"""Update DDL for this database.
Apply any configured schema from :attr:`ddl_statements`.
Expand All @@ -264,6 +264,8 @@ def update_ddl(self, ddl_statements):
:type ddl_statements: Sequence[str]
:param ddl_statements: a list of DDL statements to use on this database
:type operation_id: str
:param operation_id: a string ID for the long-running operation
:rtype: :class:`google.api_core.operation.Operation`
:returns: an operation instance
Expand All @@ -274,7 +276,7 @@ def update_ddl(self, ddl_statements):
metadata = _metadata_with_prefix(self.name)

future = api.update_database_ddl(
self.name, ddl_statements, "", metadata=metadata
self.name, ddl_statements, operation_id=operation_id, metadata=metadata
)
return future

Expand Down
34 changes: 32 additions & 2 deletions spanner/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import threading
import time
import unittest
import uuid

import pytest

Expand Down Expand Up @@ -331,12 +332,41 @@ def test_update_database_ddl(self):
self.to_delete.append(temp_db)

# We want to make sure the operation completes.
create_op.result(120) # raises on failure / timeout.
create_op.result(240) # raises on failure / timeout.

operation = temp_db.update_ddl(DDL_STATEMENTS)

# We want to make sure the operation completes.
operation.result(120) # raises on failure / timeout.
operation.result(240) # raises on failure / timeout.

temp_db.reload()

self.assertEqual(len(temp_db.ddl_statements), len(DDL_STATEMENTS))

@pytest.mark.skip(
reason=(
"update_dataset_ddl() has a flaky timeout"
"https://github.com/GoogleCloudPlatform/google-cloud-python/issues/"
"5629"
)
)
def test_update_database_ddl_with_operation_id(self):
pool = BurstyPool(labels={"testcase": "update_database_ddl"})
temp_db_id = "temp_db" + unique_resource_id("_")
temp_db = Config.INSTANCE.database(temp_db_id, pool=pool)
create_op = temp_db.create()
self.to_delete.append(temp_db)

# We want to make sure the operation completes.
create_op.result(240) # raises on failure / timeout.
# random but shortish always start with letter
operation_id = 'a' + str(uuid.uuid4())[:8]
operation = temp_db.update_ddl(DDL_STATEMENTS, operation_id=operation_id)

self.assertEqual(operation_id, operation.operation.name.split('/')[-1])

# We want to make sure the operation completes.
operation.result(240) # raises on failure / timeout.

temp_db.reload()

Expand Down

0 comments on commit 9c2d2bd

Please sign in to comment.