Skip to content

Commit 03bc7bc

Browse files
author
Jeroen van der Heijden
committed
Fix filter with ArrayValue, issue #29
1 parent e113865 commit 03bc7bc

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ build/
1818

1919
# Mac
2020
.DS_Store
21+
22+
# Json test data
23+
*.json
24+
25+
# Local test
26+
/ltest.py

aiogcd/orm/properties/arrayvalue.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def __init__(self, default=None, required=True, accept=None):
2828
super().__init__(default=default, required=required)
2929

3030
def check_value(self, value):
31-
if not isinstance(value, list):
31+
if not isinstance(value, (list, tuple)):
3232
raise TypeError(
33-
'Expecting an value of type \'int\' for property {!r} '
34-
'but received type {!r}.'
33+
'Expecting an value of type \'list\' or \'tuple\' for '
34+
'property {!r} but received type {!r}.'
3535
.format(self.name, value.__class__.__name__))
3636

3737
if self._accept and \
@@ -40,6 +40,18 @@ def check_value(self, value):
4040
'At least one item in array property {!r} has an invalid type.'
4141
.format(self.name))
4242

43+
def check_compare(self, value):
44+
"""Ignore a compare for an array value as a value van be given which
45+
filters all entities where the array contains the given value.
46+
47+
Suppose there exists an entity with an `arr` property with the array
48+
[123, 456, 789]
49+
50+
The following would return that entity:
51+
Entity.filter(Entity.arr == 456)
52+
"""
53+
pass
54+
4355
def _protect(self, value):
4456
if self._accept and not isinstance(value, self._accept):
4557
raise TypeError('Invalid type {!r} for array property {!r}.'

aiogcd/orm/properties/value.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ def descending(self):
2525
def check_value(self, value):
2626
raise NotImplementedError()
2727

28+
def check_compare(self, value):
29+
return self.check_value(value)
30+
2831
def get_value(self, model):
2932
return model.__dict__.get(self.name, None)
3033

3134
def set_value(self, model, value):
3235
Entity.set_property(model, self.name, value)
3336

3437
def _compare(self, other, op):
35-
self.check_value(other)
38+
self.check_compare(other)
3639
return {
3740
'property': {
3841
'name': self.name

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import setuptools
1616
from distutils.core import setup, Extension
1717

18-
VERSION = '0.11.12'
18+
VERSION = '0.11.13'
1919

2020
install_requires = [
2121
'aiohttp>=2',

0 commit comments

Comments
 (0)