Skip to content

Commit ed12565

Browse files
committed
Merge remote-tracking branch 'origin/master' into ticket/SG-33057-upgrade-pre-commit-hooks
2 parents 554c0ea + 9b9e538 commit ed12565

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

HISTORY.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ Flow Production Tracking Python API Changelog
44

55
Here you can see the full list of changes between each Python API release.
66

7+
v3.8.0 (2024 Feb 7)
8+
===================
9+
10+
- Extend the payload optimizations to the ``in`` and ``not_in`` filters and
11+
the ``update`` method.
12+
- The payload optimization is now enabled by default.
13+
It can be disabled with the ``SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION``
14+
environment variable.
15+
716
v3.7.0 (2024 Dec 9)
8-
===========================
17+
===================
918
- Remove unnecessary data in the payload when combining related queries before sending it to the server.
1019
This would improve overall performance decreasing network latency and server processing.
1120
See documentation for more information.

docs/reference.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,13 @@ Stores the number of milliseconds to wait between request retries. By default,
950950
In the case that both this environment variable and the config's ``rpc_attempt_interval`` property are set, the value in ``rpc_attempt_interal`` will be used.
951951

952952

953-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
953+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
954954
=======================================
955955

956956
.. note:: (v3.7.0) This is an experimental feature. Feel free to disable this feature if you are experiencing any issues.
957957

958-
When set to ``1``, this environment variable will enable the entity optimization feature.
959-
This feature is disabled by default and is used to reduce the payload size made to the server when retrieving entities
958+
When set to ``1``, this environment variable will disable the entity optimization feature.
959+
This feature is enabled by default and is used to reduce the payload size made to the server when retrieving entities
960960
improving overall performance by decreasing network latency and server processing.
961961

962962
For example, a ``find`` call like this:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name="shotgun_api3",
23-
version="3.7.0",
23+
version="3.8.0",
2424
description="Flow Production Tracking Python API",
2525
long_description=readme,
2626
author="Autodesk",

shotgun_api3/shotgun.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _is_mimetypes_broken():
109109

110110
SG_TIMEZONE = SgTimezone()
111111

112-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION = False
112+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION = False
113113

114114
NO_SSL_VALIDATION = False
115115
"""
@@ -122,7 +122,7 @@ def _is_mimetypes_broken():
122122

123123
# ----------------------------------------------------------------------------
124124
# Version
125-
__version__ = "3.7.0"
125+
__version__ = "3.8.0"
126126

127127
# ----------------------------------------------------------------------------
128128
# Errors
@@ -687,14 +687,14 @@ def __init__(
687687
"got '%s'." % self.config.rpc_attempt_interval
688688
)
689689

690-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
690+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
691691
if (
692-
os.environ.get("SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION", "0")
692+
os.environ.get("SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", "0")
693693
.strip()
694694
.lower()
695695
== "1"
696696
):
697-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION = True
697+
SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION = True
698698

699699
self._connection = None
700700

@@ -1223,14 +1223,12 @@ def _add_project_param(self, params, project_entity):
12231223
def _translate_update_params(
12241224
self, entity_type, entity_id, data, multi_entity_update_modes
12251225
):
1226-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
1226+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
12271227

12281228
def optimize_field(field_dict):
1229-
if SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION:
1230-
return {
1231-
k: _get_type_and_id_from_value(v) for k, v in field_dict.items()
1232-
}
1233-
return field_dict
1229+
if SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION:
1230+
return field_dict
1231+
return {k: _get_type_and_id_from_value(v) for k, v in field_dict.items()}
12341232

12351233
full_fields = self._dict_to_list(
12361234
data,
@@ -4864,9 +4862,9 @@ def _translate_filters_simple(sg_filter):
48644862

48654863
# Payload optimization: Do not send a full object
48664864
# just send the `type` and `id` when combining related queries
4867-
global SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
4865+
global SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
48684866
if (
4869-
SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION
4867+
not SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION
48704868
and condition["path"] != "id"
48714869
and condition["relation"] in ["is", "is_not", "in", "not_in"]
48724870
and isinstance(values[0], dict)

tests/test_unit.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def test_invalid(self):
432432
api.ShotgunError, api.shotgun._translate_filters, filters, "all"
433433
)
434434

435+
@mock.patch.dict(os.environ, {"SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION": "1"})
435436
def test_related_object(self):
436437
filters = [
437438
[
@@ -464,10 +465,11 @@ def test_related_object(self):
464465
}
465466
],
466467
}
468+
api.Shotgun("http://server_path", "script_name", "api_key", connect=False)
467469
result = api.shotgun._translate_filters(filters, "all")
468470
self.assertEqual(result, expected)
469471

470-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
472+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
471473
def test_related_object_entity_optimization_is(self):
472474
filters = [
473475
[
@@ -523,7 +525,7 @@ def test_related_object_entity_optimization_is(self):
523525
result = api.shotgun._translate_filters(filters, "all")
524526
self.assertEqual(result, expected)
525527

526-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
528+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
527529
def test_related_object_entity_optimization_in(self):
528530
filters = [
529531
[
@@ -611,7 +613,7 @@ def test_related_object_update_entity(self):
611613
)
612614
self.assertEqual(result, expected)
613615

614-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
616+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
615617
def test_related_object_update_optimization_entity(self):
616618
entity_type = "Anything"
617619
entity_id = 999
@@ -664,7 +666,7 @@ def test_related_object_update_optimization_entity(self):
664666
)
665667
self.assertEqual(result, expected)
666668

667-
@mock.patch.dict(os.environ, {"SHOTGUN_API_ENABLE_ENTITY_OPTIMIZATION": "1"})
669+
@mock.patch("shotgun_api3.shotgun.SHOTGUN_API_DISABLE_ENTITY_OPTIMIZATION", False)
668670
def test_related_object_update_optimization_entity_multi(self):
669671
entity_type = "Asset"
670672
entity_id = 6626

0 commit comments

Comments
 (0)