Skip to content

Commit 1f1c252

Browse files
committed
fix few issues with attributes
1 parent cc2e099 commit 1f1c252

4 files changed

Lines changed: 57 additions & 46 deletions

File tree

ayon_api/_api_helpers/lists.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def get_entity_lists(
5353

5454
o_fields = tuple(fields)
5555
fields = set()
56-
requires_attrib = False
56+
add_all_attrib = False
5757
for field in o_fields:
5858
if field == "attrib" or field.startswith("attrib."):
59-
requires_attrib = True
59+
add_all_attrib = True
6060
else:
6161
fields.add(field)
6262

63-
if requires_attrib:
63+
if add_all_attrib:
6464
fields.add("allAttrib")
6565

6666
if "items" in fields:
@@ -73,7 +73,7 @@ def get_entity_lists(
7373
}
7474

7575
available_attribs = {}
76-
if requires_attrib:
76+
if "allAttrib" in fields:
7777
available_attribs = self.get_attributes_for_type("list")
7878

7979
if active is not None:
@@ -98,15 +98,13 @@ def get_entity_lists(
9898
if isinstance(attributes, str):
9999
entity_list["attributes"] = json.loads(attributes)
100100

101-
if requires_attrib:
102-
attrib = json.loads(entity_list["allAttrib"])
101+
self._convert_entity_data(entity_list)
102+
103+
attrib = entity_list.get("attrib")
104+
if attrib is not None:
103105
for attrib_name, attrib_data in available_attribs.items():
104106
attrib.setdefault(attrib_name, attrib_data["default"])
105107

106-
entity_list["attrib"] = attrib
107-
108-
self._convert_entity_data(entity_list)
109-
110108
yield entity_list
111109

112110
def get_entity_list_rest(

ayon_api/_api_helpers/projects.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ def get_rest_project(
164164
return None
165165
project = response.data
166166
attrib = project["attrib"]
167-
for attr_name in self.get_attributes_for_type("project"):
168-
attrib.setdefault(attr_name, None)
167+
for attr_name, attr_data in (
168+
self.get_attributes_for_type("project").items()
169+
):
170+
attrib.setdefault(attr_name, attr_data["default"])
169171
self._fill_project_entity_data(project)
170172
return project
171173

@@ -809,6 +811,10 @@ def _get_graphql_projects(
809811
if project_name is not None:
810812
query.set_variable_value("projectName", project_name)
811813

814+
attributes = {}
815+
if "allAttrib" in fields:
816+
attributes = self.get_attributes_for_type("project")
817+
812818
for parsed_data in query.continuous_query(self):
813819
for project in parsed_data["projects"]:
814820
if active is not None and active is not project["active"]:
@@ -827,9 +833,7 @@ def _get_graphql_projects(
827833
# allAttrib would return all attribute values.
828834
project["ownAttrib"] = list(attrib)
829835
project["attrib"] = attrib
830-
for name, attr_data in (
831-
self.get_attributes_for_type("project").items()
832-
):
836+
for name, attr_data in attributes.items():
833837
# NOTE 'default' can be 'None'
834838
attrib.setdefault(name, attr_data["default"])
835839

ayon_api/constants.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
"hasPassword",
3434
"updatedAt",
3535
"apiKeyPreview",
36-
"attrib.avatarUrl",
37-
"attrib.email",
38-
"attrib.fullName",
3936
}
4037

4138
# --- Project folder types ---
@@ -104,7 +101,6 @@
104101
"linkTypes",
105102
"statuses",
106103
"tags",
107-
"attrib",
108104
}
109105

110106
# --- Folders ---

ayon_api/server_api.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
from __future__ import annotations
77

8+
import copy
89
import os
910
import re
1011
import io
@@ -1007,29 +1008,44 @@ def get_users(
10071008

10081009
if not fields:
10091010
fields = self.get_default_fields_for_type("user")
1011+
else:
1012+
fields = set(fields)
1013+
add_all_attrib = False
1014+
for field in tuple(fields):
1015+
if field == "attrib" or field.startswith("attrib."):
1016+
fields.discard(field)
1017+
add_all_attrib = True
1018+
1019+
if add_all_attrib:
1020+
fields.add("allAttrib")
10101021

1011-
query = users_graphql_query(set(fields))
1022+
query = users_graphql_query(fields)
10121023
for attr, filter_value in filters.items():
10131024
query.set_variable_value(attr, filter_value)
10141025

1015-
attributes = self.get_attributes_for_type("user")
1026+
attributes = {}
1027+
if "allAttrib" in fields:
1028+
attributes = self.get_attributes_for_type("user")
1029+
10161030
for parsed_data in query.continuous_query(self):
10171031
for user in parsed_data["users"]:
10181032
access_groups = user.get("accessGroups")
10191033
if isinstance(access_groups, str):
10201034
user["accessGroups"] = json.loads(access_groups)
1021-
all_attrib = user.get("allAttrib")
1022-
if isinstance(all_attrib, str):
1023-
user["allAttrib"] = json.loads(all_attrib)
1024-
if "attrib" in user:
1025-
user["ownAttrib"] = user["attrib"].copy()
1026-
attrib = user["attrib"]
1027-
for key, value in tuple(attrib.items()):
1028-
if value is not None:
1029-
continue
1030-
attr_def = attributes.get(key)
1031-
if attr_def is not None:
1032-
attrib[key] = attr_def["default"]
1035+
1036+
attrib = user.get("allAttrib")
1037+
if isinstance(attrib, str):
1038+
attrib = json.loads(attrib)
1039+
1040+
if attrib is not None:
1041+
own_attrib = copy.deepcopy(attrib)
1042+
user["ownAttrib"] = own_attrib
1043+
for name, attr_data in attributes.items():
1044+
attrib.setdefault(name, attr_data["default"])
1045+
own_attrib.setdefault(name, None)
1046+
1047+
user["attrib"] = attrib
1048+
10331049
yield user
10341050

10351051
def get_user_by_name(
@@ -1089,10 +1105,9 @@ def get_user(
10891105
response.raise_for_status()
10901106
user = response.data
10911107

1092-
# NOTE Server does return only filled attributes right now.
1093-
# This would fill all missing attributes with 'None'.
1094-
# for attr_name in self.get_attributes_for_type("user"):
1095-
# user["attrib"].setdefault(attr_name, None)
1108+
attributes = self.get_attributes_for_type("user")
1109+
for attr_name, attr_data in attributes.items():
1110+
user["attrib"].setdefault(attr_name, attr_data["default"])
10961111

10971112
fill_own_attribs(user)
10981113
return user
@@ -2124,6 +2139,9 @@ def get_default_fields_for_type(self, entity_type: str) -> set[str]:
21242139
if entity_type == "activity":
21252140
return set(DEFAULT_ACTIVITY_FIELDS)
21262141

2142+
if entity_type == "productType":
2143+
return set(DEFAULT_PRODUCT_TYPE_FIELDS)
2144+
21272145
if entity_type == "project":
21282146
entity_type_defaults = set(DEFAULT_PROJECT_FIELDS)
21292147
maj_v, min_v, patch_v, _, _ = self.server_version_tuple
@@ -2154,9 +2172,6 @@ def get_default_fields_for_type(self, entity_type: str) -> set[str]:
21542172
if not self.graphql_allows_traits_in_representations:
21552173
entity_type_defaults.discard("traits")
21562174

2157-
elif entity_type == "productType":
2158-
entity_type_defaults = set(DEFAULT_PRODUCT_TYPE_FIELDS)
2159-
21602175
elif entity_type == "workfile":
21612176
entity_type_defaults = set(DEFAULT_WORKFILE_INFO_FIELDS)
21622177

@@ -2165,15 +2180,13 @@ def get_default_fields_for_type(self, entity_type: str) -> set[str]:
21652180

21662181
elif entity_type == "entityList":
21672182
entity_type_defaults = set(DEFAULT_ENTITY_LIST_FIELDS)
2168-
# Attributes scope is 'list'
2169-
entity_type = "list"
21702183

21712184
else:
21722185
raise ValueError(f"Unknown entity type \"{entity_type}\"")
2173-
return (
2174-
entity_type_defaults
2175-
| self.get_attributes_fields_for_type(entity_type)
2176-
)
2186+
2187+
entity_type_defaults.add("allAttrib")
2188+
2189+
return entity_type_defaults
21772190

21782191
def get_rest_entity_by_id(
21792192
self,

0 commit comments

Comments
 (0)