Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SG-37544 Include the "in" and "not_in" operators for payload optimization #362

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions shotgun_api3/shotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4482,16 +4482,11 @@ def _translate_filters_simple(sg_filter):
if (
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
and condition["path"] != "id"
and condition["relation"] in ["is", "is_not"]
and condition["relation"] in ["is", "is_not", "in", "not_in"]
and isinstance(values[0], dict)
):
try:
values = [
{
"type": values[0]["type"],
"id": values[0]["id"],
}
]
values = [{"type": v["type"], "id": v["id"]} for v in values]
except KeyError:
pass

Expand Down
40 changes: 38 additions & 2 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
import unittest
from unittest import mock
from .mock import patch
import shotgun_api3 as api
from shotgun_api3.shotgun import _is_mimetypes_broken
Expand Down Expand Up @@ -434,7 +435,8 @@ def test_related_object(self):
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)

def test_related_object_entity_optimization(self):
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
def test_related_object_entity_optimization_is(self):
filters = [
[
"project",
Expand All @@ -457,7 +459,41 @@ def test_related_object_entity_optimization(self):
}
],
}
os.environ["SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION"] = "1"
api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)

@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
def test_related_object_entity_optimization_in(self):
filters = [
[
"project",
"in",
[
{"foo1": "foo1", "bar1": "bar1", "id": 999, "baz1": "baz1", "type": "Anything"},
{"foo2": "foo2", "bar2": "bar2", "id": 998, "baz2": "baz2", "type": "Anything"}
],
],
]
expected = {
"logical_operator": "and",
"conditions": [
{
"path": "project",
"relation": "in",
"values": [
{
"id": 999,
"type": "Anything",
},
{
"id": 998,
"type": "Anything",
}
],
}
],
}
api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
result = api.shotgun._translate_filters(filters, "all")
self.assertEqual(result, expected)
Expand Down