Skip to content

Commit a40d7ae

Browse 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 <[email protected]>
1 parent 8f187e6 commit a40d7ae

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

google/cloud/bigquery/dataset.py

+1-3
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):

tests/unit/test_dataset.py

+16
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)