|
| 1 | +# 2.0.0 Migration Guide |
| 2 | + |
| 3 | +The 2.0 release of the `google-cloud-datacatalog` client is a significant upgrade based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-python), and includes substantial interface changes. Existing code written for earlier versions of this library will likely require updates to use this version. This document describes the changes that have been made, and what you need to do to update your usage. |
| 4 | + |
| 5 | +If you experience issues or have questions, please file an [issue](https://github.com/googleapis/python-datacatalog/issues). |
| 6 | + |
| 7 | +## Supported Python Versions |
| 8 | + |
| 9 | +> **WARNING**: Breaking change |
| 10 | +The 2.0.0 release requires Python 3.6+. |
| 11 | + |
| 12 | + |
| 13 | +## Method Calls |
| 14 | + |
| 15 | +> **WARNING**: Breaking change |
| 16 | +Methods expect request objects. We provide a script that will convert most common use cases. |
| 17 | + |
| 18 | +* Install the library |
| 19 | + |
| 20 | +```py |
| 21 | +python3 -m pip install google-cloud-datacatalog |
| 22 | +``` |
| 23 | + |
| 24 | +* The script `fixup_datacatalog_v1_keywords.py` is shipped with the library. It expects |
| 25 | +an input directory (with the code to convert) and an empty destination directory. |
| 26 | + |
| 27 | +```sh |
| 28 | +$ fixup_datacatalog_v1_keywords.py --input-directory .samples/ --output-directory samples/ |
| 29 | +``` |
| 30 | + |
| 31 | +**Before:** |
| 32 | +```py |
| 33 | +from google.cloud import datacatalog_v1 |
| 34 | +datacatalog = datacatalog_v1.DataCatalogClient() |
| 35 | +return datacatalog.lookup_entry(linked_resource=resource_name) |
| 36 | +``` |
| 37 | + |
| 38 | + |
| 39 | +**After:** |
| 40 | +```py |
| 41 | +from google.cloud import datacatalog_v1 |
| 42 | +datacatalog = datacatalog_v1.DataCatalogClient() |
| 43 | +return datacatalog.lookup_entry(request={'linked_resource': resource_name}) |
| 44 | +``` |
| 45 | + |
| 46 | +### More Details |
| 47 | + |
| 48 | +In `google-cloud-datacatalog<2.0.0`, parameters required by the API were positional parameters and optional parameters were keyword parameters. |
| 49 | + |
| 50 | +**Before:** |
| 51 | +```py |
| 52 | + def create_entry_group( |
| 53 | + self, |
| 54 | + parent, |
| 55 | + entry_group_id, |
| 56 | + entry_group=None, |
| 57 | + retry=google.api_core.gapic_v1.method.DEFAULT, |
| 58 | + timeout=google.api_core.gapic_v1.method.DEFAULT, |
| 59 | + metadata=None, |
| 60 | + ): |
| 61 | +``` |
| 62 | + |
| 63 | +In the 2.0.0 release, all methods have a single positional parameter `request`. Method docstrings indicate whether a parameter is required or optional. |
| 64 | + |
| 65 | +Some methods have additional keyword only parameters. The available parameters depend on the `google.api.method_signature` annotation specified by the API producer. |
| 66 | + |
| 67 | + |
| 68 | +**After:** |
| 69 | +```py |
| 70 | + def create_entry_group( |
| 71 | + self, |
| 72 | + request: datacatalog.CreateEntryGroupRequest = None, |
| 73 | + *, |
| 74 | + parent: str = None, |
| 75 | + entry_group_id: str = None, |
| 76 | + entry_group: datacatalog.EntryGroup = None, |
| 77 | + retry: retries.Retry = gapic_v1.method.DEFAULT, |
| 78 | + timeout: float = None, |
| 79 | + metadata: Sequence[Tuple[str, str]] = (), |
| 80 | + ) -> datacatalog.EntryGroup: |
| 81 | +``` |
| 82 | + |
| 83 | +> **NOTE:** The `request` parameter and flattened keyword parameters for the API are mutually exclusive. |
| 84 | +> Passing both will result in an error. |
| 85 | +
|
| 86 | +Both of these calls are valid: |
| 87 | + |
| 88 | +```py |
| 89 | +response = client.create_entry_group( |
| 90 | + request={ |
| 91 | + "parent": parent, |
| 92 | + "entry_group_id": entry_group_id, |
| 93 | + "entry_group": entry_group |
| 94 | + } |
| 95 | +) |
| 96 | +``` |
| 97 | + |
| 98 | +```py |
| 99 | +response = client.create_entry_group( |
| 100 | + parent=parent, |
| 101 | + entry_group_id=entry_group_id, |
| 102 | + entry_group=entry_group |
| 103 | + ) # Make an API request. |
| 104 | +``` |
| 105 | + |
| 106 | +This call is invalid because it mixes `request` with a keyword argument `entry_group`. Executing this code |
| 107 | +will result in an error. |
| 108 | + |
| 109 | +```py |
| 110 | +response = client.create_entry_group( |
| 111 | + request={ |
| 112 | + "parent": parent, |
| 113 | + "entry_group_id"=entry_group_id |
| 114 | + }, |
| 115 | + entry_group=entry_group |
| 116 | +) |
| 117 | +``` |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +## Enums and Types |
| 122 | + |
| 123 | + |
| 124 | +> **WARNING**: Breaking change |
| 125 | +The submodules `enums` and `types` have been removed. |
| 126 | + |
| 127 | +**Before:** |
| 128 | +```py |
| 129 | +from google.cloud import datacatalog_v1 |
| 130 | +entry = datacatalog_v1beta1.types.Entry() |
| 131 | +entry.type = datacatalog_v1beta1.enums.EntryType.FILESET |
| 132 | +``` |
| 133 | + |
| 134 | + |
| 135 | +**After:** |
| 136 | +```py |
| 137 | +from google.cloud import datacatalog_v1 |
| 138 | +entry = datacatalog_v1beta1.Entry() |
| 139 | +entry.type = datacatalog_v1beta1.EntryType.FILESET |
| 140 | +``` |
| 141 | + |
| 142 | +## Project Path Helper Methods |
| 143 | + |
| 144 | +The project path helper method `project_path` has been removed. Please construct |
| 145 | +this path manually. |
| 146 | + |
| 147 | +```py |
| 148 | +project = 'my-project' |
| 149 | +project_path = f'projects/{project}' |
| 150 | +``` |
0 commit comments