Skip to content

Commit a54e210

Browse files
author
Takashi Matsuo
authored
fix(spanner): use uuid for unique id [(#4198)](GoogleCloudPlatform/python-docs-samples#4198)
fixes #4197 (possibly)
1 parent 8cb43c0 commit a54e210

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

samples/samples/backup_sample_test.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import random
15-
import string
14+
import uuid
1615

1716
from google.cloud import spanner
1817
import pytest
@@ -22,20 +21,17 @@
2221

2322
def unique_instance_id():
2423
""" Creates a unique id for the database. """
25-
return 'test-instance-{}'.format(''.join(random.choice(
26-
string.ascii_lowercase + string.digits) for _ in range(5)))
24+
return f'test-instance-{uuid.uuid4().hex[:10]}'
2725

2826

2927
def unique_database_id():
3028
""" Creates a unique id for the database. """
31-
return 'test-db-{}'.format(''.join(random.choice(
32-
string.ascii_lowercase + string.digits) for _ in range(5)))
29+
return f'test-db-{uuid.uuid4().hex[:10]}'
3330

3431

3532
def unique_backup_id():
3633
""" Creates a unique id for the backup. """
37-
return 'test-backup-{}'.format(''.join(random.choice(
38-
string.ascii_lowercase + string.digits) for _ in range(5)))
34+
return f'test-backup-{uuid.uuid4().hex[:10]}'
3935

4036

4137
INSTANCE_ID = unique_instance_id()

samples/samples/snippets_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
# limitations under the License.
1414

1515
import os
16-
import random
17-
import string
1816
import time
17+
import uuid
1918

2019
from google.cloud import spanner
2120
import pytest
@@ -25,8 +24,7 @@
2524

2625
def unique_database_id():
2726
""" Creates a unique id for the database. """
28-
return 'test-db-{}'.format(''.join(random.choice(
29-
string.ascii_lowercase + string.digits) for _ in range(5)))
27+
return f'test-db-{uuid.uuid4().hex[:10]}'
3028

3129

3230
INSTANCE_ID = os.environ['SPANNER_INSTANCE']

0 commit comments

Comments
 (0)