|
| 1 | +<!-- |
| 2 | +Copyright 2020 Google LLC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | + |
| 18 | +# 2.0.0 Migration Guide |
| 19 | + |
| 20 | +The 2.0 release of the `google-cloud-bigquery-datatransfer` client is a significant |
| 21 | +upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), |
| 22 | +and includes substantial interface changes. Existing code written for earlier versions |
| 23 | +of this library will likely require updates to use this version. This document |
| 24 | +describes the changes that have been made, and what you need to do to update your usage. |
| 25 | + |
| 26 | +If you experience issues or have questions, please file an |
| 27 | +[issue](https://github.com/googleapis/python-bigquery-datatransfer/issues). |
| 28 | + |
| 29 | + |
| 30 | +## Supported Python Versions |
| 31 | + |
| 32 | +> **WARNING**: Breaking change |
| 33 | +
|
| 34 | +The 2.0.0 release requires Python 3.6+. |
| 35 | + |
| 36 | + |
| 37 | +## Import Path |
| 38 | + |
| 39 | +> **WARNING**: Breaking change |
| 40 | +
|
| 41 | +The library was moved into `google.cloud.bigquery` namespace. Existing imports |
| 42 | +need to be updated. |
| 43 | + |
| 44 | +**Before:** |
| 45 | +```py |
| 46 | +from google.cloud import bigquery_datatransfer |
| 47 | +from google.cloud import bigquery_datatransfer_v1 |
| 48 | +``` |
| 49 | + |
| 50 | +**After:** |
| 51 | +```py |
| 52 | +from google.cloud.bigquery import datatransfer |
| 53 | +from google.cloud.bigquery import datatransfer_v1 |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | +## Method Calls |
| 58 | + |
| 59 | +> **WARNING**: Breaking change |
| 60 | +
|
| 61 | +Methods that send requests to the backend expect request objects. We provide a script |
| 62 | +that will convert most common use cases. |
| 63 | + |
| 64 | +* Install the library |
| 65 | + |
| 66 | +```py |
| 67 | +python3 -m pip install google-cloud-bigquery-datatransfer |
| 68 | +``` |
| 69 | + |
| 70 | +* The script `fixup_datatransfer_v1_keywords.py` is shipped with the library. It expects |
| 71 | +an input directory (with the code to convert) and an empty destination directory. |
| 72 | + |
| 73 | +```sh |
| 74 | +$ scripts/fixup_datatransfer_v1_keywords.py --input-directory .samples/ --output-directory samples/ |
| 75 | +``` |
| 76 | + |
| 77 | +**Before:** |
| 78 | +```py |
| 79 | +from google.cloud import bigquery_datatransfer |
| 80 | + |
| 81 | +client = bigquery_datatransfer.DataTransferServiceClient() |
| 82 | + |
| 83 | +parent_project = "..." |
| 84 | +transfer_config = {...} |
| 85 | +authorization_code = "..." |
| 86 | + |
| 87 | +response = client.create_transfer_config( |
| 88 | + parent_project, transfer_config, authorization_code=authorization_code |
| 89 | +) |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | +**After:** |
| 94 | +```py |
| 95 | +from google.cloud.bigquery import datatransfer |
| 96 | + |
| 97 | +client = datatransfer.DataTransferServiceClient() |
| 98 | + |
| 99 | +parent_project = "..." |
| 100 | +transfer_config = {...} |
| 101 | +authorization_code = "..." |
| 102 | + |
| 103 | +response = client.create_transfer_config( |
| 104 | + request={ |
| 105 | + "parent": parent_project, |
| 106 | + "transfer_config": transfer_config, |
| 107 | + "authorization_code": authorization_code, |
| 108 | + } |
| 109 | +) |
| 110 | +``` |
| 111 | + |
| 112 | +### More Details |
| 113 | + |
| 114 | +In `google-cloud-bigquery-datatransfer<2.0.0`, parameters required by the API were positional |
| 115 | +parameters and optional parameters were keyword parameters. |
| 116 | + |
| 117 | +**Before:** |
| 118 | +```py |
| 119 | +def create_transfer_config( |
| 120 | + self, |
| 121 | + parent, |
| 122 | + transfer_config, |
| 123 | + authorization_code=None, |
| 124 | + version_info=None, |
| 125 | + service_account_name=None, |
| 126 | + retry=google.api_core.gapic_v1.method.DEFAULT, |
| 127 | + timeout=google.api_core.gapic_v1.method.DEFAULT, |
| 128 | + metadata=None, |
| 129 | +): |
| 130 | +``` |
| 131 | + |
| 132 | +In the `2.0.0` release, methods that interact with the backend have a single |
| 133 | +positional parameter `request`. Method docstrings indicate whether a parameter is |
| 134 | +required or optional. |
| 135 | + |
| 136 | +Some methods have additional keyword only parameters. The available parameters depend |
| 137 | +on the [`google.api.method_signature` annotation](https://github.com/googleapis/python-bigquery-datatransfer/blob/master/google/cloud/bigquery_datatransfer_v1/proto/datatransfer.proto#L80) |
| 138 | +specified by the API producer. |
| 139 | + |
| 140 | + |
| 141 | +**After:** |
| 142 | +```py |
| 143 | +def create_transfer_config( |
| 144 | + self, |
| 145 | + request: datatransfer.CreateTransferConfigRequest = None, |
| 146 | + *, |
| 147 | + parent: str = None, |
| 148 | + transfer_config: transfer.TransferConfig = None, |
| 149 | + retry: retries.Retry = gapic_v1.method.DEFAULT, |
| 150 | + timeout: float = None, |
| 151 | + metadata: Sequence[Tuple[str, str]] = (), |
| 152 | +) -> transfer.TransferConfig: |
| 153 | +``` |
| 154 | + |
| 155 | +> **NOTE:** The `request` parameter and flattened keyword parameters for the API are |
| 156 | +> mutually exclusive. Passing both will result in an error. |
| 157 | +
|
| 158 | + |
| 159 | +Both of these calls are valid: |
| 160 | + |
| 161 | +```py |
| 162 | +response = client.create_transfer_config( |
| 163 | + request={ |
| 164 | + "parent": project_path, |
| 165 | + "transfer_config": {"foo": "bar"}, |
| 166 | + } |
| 167 | +) |
| 168 | +``` |
| 169 | + |
| 170 | +```py |
| 171 | +response = client.create_transfer_config( |
| 172 | + parent=project_path, |
| 173 | + transfer_config={"foo": "bar"}, |
| 174 | +) |
| 175 | +``` |
| 176 | + |
| 177 | +This call is _invalid_ because it mixes `request` with a keyword argument `transfer_config`. |
| 178 | +Executing this code will result in an error: |
| 179 | + |
| 180 | +```py |
| 181 | +response = client.synthesize_speech( |
| 182 | + request={"parent": project_path}, |
| 183 | + transfer_config= {"foo": "bar"}, |
| 184 | +) |
| 185 | +``` |
| 186 | + |
| 187 | +> **NOTE:** The `request` parameter of some methods can also contain a more rich set of |
| 188 | +> options that are otherwise not available as explicit keyword only parameters, thus |
| 189 | +> these _must_ be passed through `request`. |
| 190 | +
|
| 191 | + |
| 192 | +## Removed Utility Methods |
| 193 | + |
| 194 | +> **WARNING**: Breaking change |
| 195 | +
|
| 196 | +Most utility methods such as `project_path()` have been removed. The paths must |
| 197 | +now be constructed manually: |
| 198 | + |
| 199 | +```py |
| 200 | +project_path = f"project/{PROJECT_ID}" |
| 201 | +``` |
| 202 | + |
| 203 | + The only two that remained are `transfer_config_path()` and `parse_transfer_config_path()`. |
| 204 | + |
| 205 | + |
| 206 | +## Removed `client_config` Parameter |
| 207 | + |
| 208 | +The client cannot be constructed with `client_config` argument anymore, this deprecated |
| 209 | +argument has been removed. If you want to customize retry and timeout settings for a particular |
| 210 | +method, you need to do it upon method invocation by passing the custom `timeout` and |
| 211 | +`retry` arguments, respectively. |
0 commit comments