diff --git a/datastore/gcloud/aio/datastore/filter.py b/datastore/gcloud/aio/datastore/filter.py index bc0823635..a00949d01 100644 --- a/datastore/gcloud/aio/datastore/filter.py +++ b/datastore/gcloud/aio/datastore/filter.py @@ -122,10 +122,13 @@ def to_repr(self) -> Dict[str, Any]: # TODO: consider refactoring to look more like Value.to_repr() if isinstance(self.value, Array): rep['value'] = {'arrayValue': self.value.to_repr()} - elif isinstance(self.value, Value) and isinstance(self.value.value, list): - # This is a special case where the value is type of Value, but its value is a list - rep['value'] = {'arrayValue': {'values': [Value(x).to_repr() for x in - self.value.value]}} + elif (isinstance(self.value, Value) + and isinstance(self.value.value, list)): + # This allows for a bit of syntactic sugar such that folks can pass + # in a list directly (ie. as a Value instead of as an Array, as the + # Google APIs would return it). + values = [Value(x).to_repr() for x in self.value.value] + rep['value'] = {'arrayValue': {'values': values}} else: rep['value'] = self.value.to_repr() return rep diff --git a/datastore/tests/unit/filter_test.py b/datastore/tests/unit/filter_test.py index 57ecdf3d0..8f822b003 100644 --- a/datastore/tests/unit/filter_test.py +++ b/datastore/tests/unit/filter_test.py @@ -135,9 +135,14 @@ def test_repr_returns_to_repr_as_string(query_filter): assert repr(query_filter) == str(query_filter.to_repr()) def test_in_filter_with_list_arg(self): - expected_value = {'arrayValue': { - 'values': [{'excludeFromIndexes': False, 'stringValue': 'value1'}, - {'excludeFromIndexes': False, 'stringValue': 'value2'}]}} + expected_value = { + 'arrayValue': { + 'values': [ + {'excludeFromIndexes': False, 'stringValue': 'value1'}, + {'excludeFromIndexes': False, 'stringValue': 'value2'}, + ], + }, + } prop = 'prop1' value = ['value1', 'value2']