Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a40d7ae

Browse filesBrowse files
fix: AccessEntry API representation parsing (#1682)
* fix: AccessEntry API representation parsing Overriding the `AccessEntry#_properties` with a deep copy of the API resource overwrites the `role` property set in `AccessEntry.__init__` which isn't present in the resource if the `role` is set to `None`. This causes `AccessEntry`s generated from API representations to no longer evaluate to equal with equivalent `AccessEntry` resources instantiated through `AccessEntry.__init__`. The added unit test fails without the change and passes with the change. * build: formatting --------- Co-authored-by: Lingqing Gan <lingqing.gan@gmail.com>
1 parent 8f187e6 commit a40d7ae
Copy full SHA for a40d7ae

File tree

Expand file treeCollapse file tree

2 files changed

+17
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-3
lines changed
Open diff view settings
Collapse file

‎google/cloud/bigquery/dataset.py‎

Copy file name to clipboardExpand all lines: google/cloud/bigquery/dataset.py
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,7 @@ def from_api_repr(cls, resource: dict) -> "AccessEntry":
501501
if len(entry) != 0:
502502
raise ValueError("Entry has unexpected keys remaining.", entry)
503503

504-
config = cls(role, entity_type, entity_id)
505-
config._properties = copy.deepcopy(resource)
506-
return config
504+
return cls(role, entity_type, entity_id)
507505

508506

509507
class Dataset(object):
Collapse file

‎tests/unit/test_dataset.py‎

Copy file name to clipboardExpand all lines: tests/unit/test_dataset.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ def test_from_api_repr_w_unknown_entity_type(self):
152152
exp_resource = entry.to_api_repr()
153153
self.assertEqual(resource, exp_resource)
154154

155+
def test_from_api_repr_wo_role(self):
156+
resource = {
157+
"view": {
158+
"projectId": "my-project",
159+
"datasetId": "my_dataset",
160+
"tableId": "my_table",
161+
}
162+
}
163+
entry = self._get_target_class().from_api_repr(resource)
164+
exp_entry = self._make_one(
165+
role=None,
166+
entity_type="view",
167+
entity_id=resource["view"],
168+
)
169+
self.assertEqual(entry, exp_entry)
170+
155171
def test_to_api_repr_w_extra_properties(self):
156172
resource = {
157173
"role": "READER",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.