Skip to content

Conversation

kevinwchin
Copy link

Description

Adds a Python sample to disable a BQ DTS transfer configuration. We're missing a sample here in https://cloud.google.com/bigquery/docs/working-with-transfers#disable_a_transfer

Checklist

Adds a Python sample to disable a BQ DTS transfer configuration.
@kevinwchin kevinwchin requested review from a team as code owners September 26, 2025 18:48
Copy link

snippet-bot bot commented Sep 26, 2025

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 26, 2025
Copy link
Contributor

Summary of Changes

Hello @kevinwchin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Python sample to the bigquery-datatransfer snippets, specifically within the manage_transfer_configs.py file. The primary purpose of this sample is to provide a clear example of how to programmatically disable a BigQuery Data Transfer Service configuration, addressing a previously missing piece of documentation for this common task.

Highlights

  • New Sample Added: A new Python sample, disable_config, has been added to manage_transfer_configs.py.
  • BigQuery DTS Configuration Management: This sample demonstrates how to disable an existing BigQuery Data Transfer Service (DTS) transfer configuration.
  • Documentation Gap Addressed: The addition of this sample fills a gap in the official BigQuery DTS documentation regarding disabling transfers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new sample for disabling a BigQuery DTS transfer configuration. The implementation is straightforward, but it's missing a corresponding test case, which is a critical omission for ensuring the sample works correctly. I've also provided a couple of suggestions to improve the code's robustness and readability by addressing a common Python pitfall and improving the clarity of a client library call. Please add the test and consider the other suggestions.

Comment on lines +107 to +137
def disable_config(override_values={}):
# [START bigquerydatatransfer_disable_config]
from google.cloud import bigquery_datatransfer
from google.protobuf import field_mask_pb2

transfer_client = bigquery_datatransfer.DataTransferServiceClient()

transfer_config_name = "projects/1234/locations/us/transferConfigs/abcd"
# [END bigquerydatatransfer_disable_config]
# To facilitate testing, we replace values with alternatives
# provided by the testing harness.
transfer_config_name = override_values.get(
"transfer_config_name", transfer_config_name
)
# [START bigquerydatatransfer_disable_config]

transfer_config = bigquery_datatransfer.TransferConfig(name=transfer_config_name)
transfer_config.disabled = True

transfer_config = transfer_client.update_transfer_config(
{
"transfer_config": transfer_config,
"update_mask": field_mask_pb2.FieldMask(paths=["disabled"]),
}
)

print(f"Updated config: '{transfer_config.name}'")
print(f"Is config disabled: '{transfer_config.disabled}'")
# [END bigquerydatatransfer_disable_config]
# Return the config name for testing purposes, so that it can be deleted.
return transfer_config
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The newly added disable_config function is missing a corresponding unit test in manage_transfer_configs_test.py. Adding a test is essential to verify the functionality of this sample and prevent future regressions. Please add a test that calls this function and asserts that the transfer config is disabled correctly.

# Return the config name for testing purposes, so that it can be deleted.
return transfer_config

def disable_config(override_values={}):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using a mutable object like a dictionary as a default argument can lead to unexpected behavior if it's ever modified, as the modification will persist across calls. It's safer to use None as the default.1

After applying this suggestion, please add the following lines at the beginning of the function body:

    if override_values is None:
        override_values = {}

This pattern is used throughout the file and should ideally be corrected everywhere for consistency and robustness.

Suggested change
def disable_config(override_values={}):
def disable_config(override_values=None):

Style Guide References

Footnotes

  1. Avoid using mutable default arguments in function definitions. Instead, use a default value of None and initialize the mutable type within the function. This prevents hard-to-debug issues where a default object is modified and that modification persists across function calls.

Comment on lines +126 to +131
transfer_config = transfer_client.update_transfer_config(
{
"transfer_config": transfer_config,
"update_mask": field_mask_pb2.FieldMask(paths=["disabled"]),
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better readability, consider using keyword arguments when calling update_transfer_config instead of passing a dictionary. This makes the call more explicit and easier to understand at a glance.

    transfer_config = transfer_client.update_transfer_config(
        transfer_config=transfer_config,
        update_mask=field_mask_pb2.FieldMask(paths=["disabled"]),
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant