Skip to content
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
1 change: 0 additions & 1 deletion librarian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3541,7 +3541,6 @@ libraries:
- docs/spanner_v1/table.rst
- docs/spanner_v1/transaction.rst
- tests/unit/gapic/conftest.py
skip_generate: true
python:
library_type: GAPIC_COMBO
opt_args_by_api:
Expand Down
24 changes: 11 additions & 13 deletions packages/google-cloud-spanner/.repo-metadata.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"name": "spanner",
"name_pretty": "Cloud Spanner",
"product_documentation": "https://cloud.google.com/spanner/docs/",
"api_description": "is the world's first fully managed relational database service \nto offer both strong consistency and horizontal scalability for \nmission-critical online transaction processing (OLTP) applications. With Cloud \nSpanner you enjoy all the traditional benefits of a relational database; but \nunlike any other relational database service, Cloud Spanner scales horizontally \nto hundreds or thousands of servers to handle the biggest transactional \nworkloads.",
"api_id": "spanner.googleapis.com",
"api_shortname": "spanner",
"client_documentation": "https://cloud.google.com/python/docs/reference/spanner/latest",
"default_version": "v1",
"distribution_name": "google-cloud-spanner",
"issue_tracker": "https://issuetracker.google.com/issues?q=componentid:190851%2B%20status:open",
"release_level": "stable",
"language": "python",
"library_type": "GAPIC_COMBO",
"repo": "googleapis/google-cloud-python",
"distribution_name": "google-cloud-spanner",
"api_id": "spanner.googleapis.com",
"requires_billing": true,
"default_version": "v1",
"codeowner_team": "@googleapis/spanner-team",
"api_shortname": "spanner",
"api_description": "is the world's first fully managed relational database service \nto offer both strong consistency and horizontal scalability for \nmission-critical online transaction processing (OLTP) applications. With Cloud \nSpanner you enjoy all the traditional benefits of a relational database; but \nunlike any other relational database service, Cloud Spanner scales horizontally \nto hundreds or thousands of servers to handle the biggest transactional \nworkloads."
}
"name": "spanner",
"name_pretty": "Cloud Spanner",
"product_documentation": "https://cloud.google.com/spanner/docs/",
"release_level": "stable",
"repo": "googleapis/google-cloud-python"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# -*- coding: utf-8 -*-

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: benchmark/benchwrapper/proto/spanner.proto
"""Generated protocol buffer code."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def create_backup_with_encryption_key(
instance_id, database_id, backup_id, kms_key_name
):
"""Creates a backup for a database using a Customer Managed Encryption Key (CMEK)."""
from google.cloud.spanner_admin_database_v1 import \
CreateBackupEncryptionConfig
from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig

spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
Expand Down Expand Up @@ -187,8 +186,7 @@ def create_database_with_version_retention_period(
+ " AlbumTitle STRING(MAX)"
+ ") PRIMARY KEY (SingerId, AlbumId),"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE",
"ALTER DATABASE `{}`"
" SET OPTIONS (version_retention_period = '{}')".format(
"ALTER DATABASE `{}` SET OPTIONS (version_retention_period = '{}')".format(
database_id, retention_period
),
]
Expand Down Expand Up @@ -396,8 +394,7 @@ def restore_database_with_encryption_key(
instance_id, new_database_id, backup_id, kms_key_name
):
"""Restores a database from a backup using a Customer Managed Encryption Key (CMEK)."""
from google.cloud.spanner_admin_database_v1 import \
RestoreDatabaseEncryptionConfig
from google.cloud.spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig

spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def test_create_backup_with_encryption_key(
assert kms_key_name in out


@pytest.mark.skip(reason="same test passes on unarchived test suite, "
"but fails here. Needs investigation")
@pytest.mark.skip(
reason="same test passes on unarchived test suite, "
"but fails here. Needs investigation"
)
@pytest.mark.dependency(depends=["create_backup"])
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
def test_restore_database(capsys, instance_id, sample_database):
Expand All @@ -103,8 +105,10 @@ def test_restore_database(capsys, instance_id, sample_database):
assert BACKUP_ID in out


@pytest.mark.skip(reason="same test passes on unarchived test suite, "
"but fails here. Needs investigation")
@pytest.mark.skip(
reason="same test passes on unarchived test suite, "
"but fails here. Needs investigation"
)
@pytest.mark.dependency(depends=["create_backup_with_encryption_key"])
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
def test_restore_database_with_encryption_key(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Spanner PostgreSql dialect.
For more information, see the README.rst under /spanner.
"""

from google.cloud import spanner, spanner_admin_database_v1
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import pg_samples as samples
import pytest
from google.api_core import exceptions
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
from test_utils.retry import RetryErrors

from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect

CREATE_TABLE_SINGERS = """\
CREATE TABLE Singers (
SingerId BIGINT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@

import time

from google.cloud import spanner
from google.iam.v1 import policy_pb2
from google.type import expr_pb2

from google.cloud import spanner

OPERATION_TIMEOUT_SECONDS = 240


Expand Down Expand Up @@ -293,8 +294,9 @@ def create_database_with_default_leader(instance_id, database_id, default_leader
AlbumTitle STRING(MAX)
) PRIMARY KEY (SingerId, AlbumId),
INTERLEAVE IN PARENT Singers ON DELETE CASCADE""",
"ALTER DATABASE {}"
" SET OPTIONS (default_leader = '{}')".format(database_id, default_leader),
"ALTER DATABASE {} SET OPTIONS (default_leader = '{}')".format(
database_id, default_leader
),
],
)
operation = database.create()
Expand Down Expand Up @@ -806,8 +808,9 @@ def update_database_with_default_leader(instance_id, database_id, default_leader

operation = database.update_ddl(
[
"ALTER DATABASE {}"
" SET OPTIONS (default_leader = '{}')".format(database_id, default_leader)
"ALTER DATABASE {} SET OPTIONS (default_leader = '{}')".format(
database_id, default_leader
)
]
)
operation.result(OPERATION_TIMEOUT_SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

import pytest
from google.api_core import exceptions
from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
from test_utils.retry import RetryErrors

import samples
from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect

CREATE_TABLE_SINGERS = """\
CREATE TABLE Singers (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

import pytest
from google.api_core.exceptions import Aborted
import pytest
from test_utils.retry import RetryErrors

import autocommit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,7 @@ def create_database_with_version_retention_period(
+ " AlbumTitle STRING(MAX)"
+ ") PRIMARY KEY (SingerId, AlbumId),"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE",
"ALTER DATABASE `{}`"
" SET OPTIONS (version_retention_period = '{}')".format(
"ALTER DATABASE `{}` SET OPTIONS (version_retention_period = '{}')".format(
database_id, retention_period
),
]
Expand Down Expand Up @@ -706,8 +705,8 @@ def copy_backup_with_multiple_kms_keys(
):
"""Copies a backup."""

from google.cloud.spanner_admin_database_v1.types import backup as backup_pb
from google.cloud.spanner_admin_database_v1 import CopyBackupEncryptionConfig
from google.cloud.spanner_admin_database_v1.types import backup as backup_pb

spanner_client = spanner.Client()
database_admin_api = spanner_client.database_admin_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_create_backup_with_encryption_key(
assert kms_key_name in out


@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " "project")
@pytest.mark.skip(reason="skipped since the KMS keys are not added on test project")
@pytest.mark.dependency(name="create_backup_with_multiple_kms_keys")
def test_create_backup_with_multiple_kms_keys(
capsys,
Expand All @@ -115,7 +115,7 @@ def test_create_backup_with_multiple_kms_keys(
assert kms_key_names[2] in out


@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " "project")
@pytest.mark.skip(reason="skipped since the KMS keys are not added on test project")
@pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"])
def test_copy_backup_with_multiple_kms_keys(
capsys, multi_region_instance_id, spanner_client, kms_key_names
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_restore_database_with_encryption_key(
assert kms_key_name in out


@pytest.mark.skip(reason="skipped since the KMS keys are not added on test " "project")
@pytest.mark.skip(reason="skipped since the KMS keys are not added on test project")
@pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"])
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
def test_restore_database_with_multiple_kms_keys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"""

import argparse

from enum import Enum


Expand All @@ -29,14 +28,15 @@ def create_full_backup_schedule(
schedule_id: str,
) -> None:
from datetime import timedelta

from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types import (
backup_schedule as backup_schedule_pb,
)
from google.cloud.spanner_admin_database_v1.types import (
CreateBackupEncryptionConfig,
FullBackupSpec,
)
from google.cloud.spanner_admin_database_v1.types import (
backup_schedule as backup_schedule_pb,
)
Comment on lines 33 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These redundant imports from the same module can be merged into a single block for better readability and to avoid redundancy. This aligns with the rule to remove duplicate or redundant code to keep the codebase clean.

    from google.cloud.spanner_admin_database_v1.types import (
        CreateBackupEncryptionConfig,
        FullBackupSpec,
        backup_schedule as backup_schedule_pb,
    )
References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.


client = spanner.Client()
database_admin_api = client.database_admin_api
Expand Down Expand Up @@ -74,14 +74,15 @@ def create_incremental_backup_schedule(
schedule_id: str,
) -> None:
from datetime import timedelta

from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types import (
backup_schedule as backup_schedule_pb,
)
from google.cloud.spanner_admin_database_v1.types import (
CreateBackupEncryptionConfig,
IncrementalBackupSpec,
)
from google.cloud.spanner_admin_database_v1.types import (
backup_schedule as backup_schedule_pb,
)
Comment on lines 79 to +85
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These redundant imports from the same module can be merged into a single block for better readability and to avoid redundancy. This aligns with the rule to remove duplicate or redundant code to keep the codebase clean.

    from google.cloud.spanner_admin_database_v1.types import (
        CreateBackupEncryptionConfig,
        IncrementalBackupSpec,
        backup_schedule as backup_schedule_pb,
    )
References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.


client = spanner.Client()
database_admin_api = client.database_admin_api
Expand Down Expand Up @@ -174,12 +175,13 @@ def update_backup_schedule(
schedule_id: str,
) -> None:
from datetime import timedelta

from google.cloud import spanner
from google.cloud.spanner_admin_database_v1.types import (
backup_schedule as backup_schedule_pb,
CreateBackupEncryptionConfig,
)
from google.cloud.spanner_admin_database_v1.types import (
CreateBackupEncryptionConfig,
backup_schedule as backup_schedule_pb,
)
Comment on lines 180 to 185
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These redundant imports from the same module can be merged into a single block for better readability and to avoid redundancy. This aligns with the rule to remove duplicate or redundant code to keep the codebase clean.

    from google.cloud.spanner_admin_database_v1.types import (
        CreateBackupEncryptionConfig,
        backup_schedule as backup_schedule_pb,
    )
References
  1. Remove duplicate lines of code, especially duplicate assertions in tests, to keep the codebase clean and avoid redundancy.

from google.protobuf.field_mask_pb2 import FieldMask

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import backup_schedule_samples as samples
import pytest
import uuid

import pytest

import backup_schedule_samples as samples

__FULL_BACKUP_SCHEDULE_ID = "full-backup-schedule"
__INCREMENTAL_BACKUP_SCHEDULE_ID = "incremental-backup-schedule"
Expand Down
4 changes: 2 additions & 2 deletions packages/google-cloud-spanner/samples/samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Shared pytest fixtures."""
"""Shared pytest fixtures."""

import time
import uuid

from google.api_core import exceptions
from google.cloud import spanner_admin_database_v1
from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin
from google.cloud.spanner_v1 import backup, client, database, instance
import pytest
from test_utils import retry
from google.cloud.spanner_admin_instance_v1.types import spanner_instance_admin

INSTANCE_CREATION_TIMEOUT = 560 # seconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

# import time
import uuid
import pytest

from google.api_core import exceptions

from google.cloud.spanner_admin_database_v1.types.common import DatabaseDialect
import pytest
from test_utils.retry import RetryErrors

import graph_snippets
Expand Down
Loading
Loading