Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 635a1f4

Browse files
committed
Updates DatasetReference in test and __eq__ check
1 parent 9a6f0b6 commit 635a1f4

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

google/cloud/bigquery/dataset.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ def dataset(self, value):
333333
if isinstance(value, str):
334334
value = DatasetReference.from_string(value).to_api_repr()
335335

336+
if isinstance(value, DatasetReference):
337+
value = value.to_api_repr()
338+
336339
if isinstance(value, (Dataset, DatasetListItem)):
337340
value = value.reference.to_api_repr()
338341

@@ -1222,19 +1225,29 @@ def __eq__(self, other: object) -> bool:
12221225
"""Check for equality based on expression, title, and description."""
12231226
if not isinstance(other, Condition):
12241227
return NotImplemented
1225-
return (
1226-
self.expression == other.expression
1227-
and self.title == other.title
1228-
and self.description == other.description
1229-
)
1228+
return self._key() == other._key()
1229+
1230+
def _key(self):
1231+
"""A tuple key that uniquely describes this field.
1232+
Used to compute this instance's hashcode and evaluate equality.
1233+
Returns:
1234+
Tuple: The contents of this :class:`~google.cloud.bigquery.dataset.AccessEntry`.
1235+
"""
1236+
1237+
properties = self._properties.copy()
1238+
1239+
# Dicts are not hashable.
1240+
# Convert object to a hashable datatype(s)
1241+
prop_tup = tuple(sorted(properties.items()))
1242+
return prop_tup
12301243

12311244
def __ne__(self, other: object) -> bool:
12321245
"""Check for inequality."""
12331246
return not self == other
12341247

12351248
def __hash__(self) -> int:
12361249
"""Generate a hash based on expression, title, and description."""
1237-
return hash((self.expression, self.title, self.description))
1250+
return hash(self._key())
12381251

12391252
def __repr__(self) -> str:
12401253
"""Return a string representation of the Condition object."""

tests/unit/test_dataset.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ def test_dataset_getter_setter_dataset_ref(self):
301301
entry.dataset = dataset_ref
302302
resource = entry.to_api_repr()
303303
exp_resource = {
304-
"dataset": {"dataset": dataset_ref, "targetTypes": None},
304+
"dataset": {
305+
"dataset": {"datasetId": "my_dataset", "projectId": "my-project"},
306+
"targetTypes": None,
307+
},
305308
"role": None,
306309
}
307310
self.assertEqual(resource, exp_resource)
@@ -726,10 +729,16 @@ def test_dataset_property_with_condition(self, condition_1):
726729
entry.condition = condition_1
727730

728731
resource = entry.to_api_repr()
732+
print(
733+
f"""
734+
DINOSAUR:
735+
{resource}
736+
"""
737+
)
729738
exp_resource = {
730739
"role": None,
731740
"dataset": {
732-
"dataset": DatasetReference("my-project", "my_dataset"),
741+
"dataset": {"datasetId": "my_dataset", "projectId": "my-project"},
733742
"targetTypes": None,
734743
},
735744
"condition": {

0 commit comments

Comments
 (0)