Skip to content

Commit b78282f

Browse files
author
kbehrman
committed
Ticket #18451 modified to allow list values as arguments
1 parent 1fa9b9a commit b78282f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

shotgun_api3/shotgun.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,16 @@ def _translate_filters(filters, filter_operator):
17531753
new_filters["logical_operator"] = "and"
17541754
else:
17551755
new_filters["logical_operator"] = "or"
1756-
conditions = [{"path":f[0], "relation":f[1], "values":f[2:]}
1757-
for f in filters]
1756+
1757+
conditions = []
1758+
for sg_filter in filters:
1759+
condition = {"path": sg_filter[0], "relation": sg_filter[1]}
1760+
values = sg_filter[2:]
1761+
if len(values) == 1 and isinstance(values[0], (list, tuple)):
1762+
values = values[0]
1763+
1764+
condition["values"] = values
1765+
conditions.append(condition)
1766+
17581767
new_filters["conditions"] = conditions
17591768
return new_filters

tests/test_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ def test_find(self):
119119
self.assertEqual("Version", version["type"])
120120
self.assertEqual(self.version['id'], version["id"])
121121

122+
def test_find_in(self):
123+
"""Test use of 'in' relation with find."""
124+
# id
125+
filters = [['id', 'in', [self.project['id'], 99999]]]
126+
projects = self.sg.find('Project', filters)
127+
self.assertTrue(any(r['id'] == self.project['id'] for r in projects))
128+
129+
# text field
130+
filters = [['name', 'in', [self.project['name'], 'fake project name']]]
131+
projects = self.sg.find('Project', filters)
132+
project = projects[0]
133+
self.assertEqual(self.project['id'], project['id'])
134+
135+
136+
122137
def test_last_accessed(self):
123138
page = self.sg.find('Page', [], fields=['last_accessed'], limit=1)
124139
self.assertEqual("Page", page[0]['type'])

0 commit comments

Comments
 (0)