Skip to content

Commit a98bce0

Browse files
committed
few more fixes
1 parent 9d38668 commit a98bce0

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

ayon_api/_api_helpers/projects.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,10 @@ def get_rest_projects_list(
197197
"active": active,
198198
"library": library,
199199
})
200-
201200
response = self.get(f"projects{query}")
202201
response.raise_for_status()
203202
data = response.data
204-
if data:
205-
return data["projects"]
206-
return []
203+
return data["projects"]
207204

208205
def get_project_names(
209206
self,
@@ -257,7 +254,8 @@ def get_projects(
257254

258255
graphql_fields, fetch_type = self._get_project_graphql_fields(fields)
259256
if fetch_type == ProjectFetchType.RESTList:
260-
return self.get_rest_projects_list(active, library)
257+
yield from self.get_rest_projects_list(active, library)
258+
return
261259

262260
projects_by_name = {}
263261
if graphql_fields:
@@ -275,7 +273,7 @@ def get_projects(
275273
for project in self.get_rest_projects(active, library):
276274
name = project["name"]
277275
graphql_p = projects_by_name.get(name)
278-
if graphql_p:
276+
if graphql_p and "productTypes" in graphql_p:
279277
project["productTypes"] = graphql_p["productTypes"]
280278
yield project
281279

@@ -667,19 +665,24 @@ def _get_project_graphql_fields(
667665

668666
elif field.startswith("productBaseTypes"):
669667
has_product_types = True
670-
graphql_fields.add("productBaseTypes.name")
668+
graphql_fields.add(field)
669+
670+
elif field == "bundle" or field == "bundles":
671+
fields.discard(field)
672+
graphql_fields.add("bundle.production")
673+
graphql_fields.add("bundle.staging")
671674

672-
elif field == "bundles":
673-
fields.discard("bundles")
674-
graphql_fields.add("bundles.production")
675-
graphql_fields.add("bundles.staging")
675+
elif field.startswith("bundle"):
676+
graphql_fields.add(field)
676677

677678
elif field == "attrib":
678679
fields.discard("attrib")
679680
graphql_fields |= self.get_attributes_fields_for_type(
680681
"project"
681682
)
682683

684+
# NOTE 'config' in GraphQl is NOT the same as from REST api.
685+
# - At the moment of this comment there is missing 'productBaseTypes'.
683686
inters = fields & {
684687
"name",
685688
"code",
@@ -693,13 +696,11 @@ def _get_project_graphql_fields(
693696
graphql_fields |= inters
694697
return graphql_fields, ProjectFetchType.GraphQl
695698

696-
graphql_fields.add("name")
697-
fetch_type = (
698-
ProjectFetchType.GraphQlAndREST
699-
if has_product_types
700-
else ProjectFetchType.REST
701-
)
702-
return graphql_fields, fetch_type
699+
if has_product_types:
700+
graphql_fields.add("name")
701+
return graphql_fields, ProjectFetchType.GraphQlAndREST
702+
703+
return set(), ProjectFetchType.REST
703704

704705
def _fill_project_entity_data(self, project: dict[str, Any]) -> None:
705706
# Add fake scope to statuses if not available
@@ -727,7 +728,7 @@ def _fill_project_entity_data(self, project: dict[str, Any]) -> None:
727728

728729
# Fill 'bundle' from data if is not filled
729730
if "bundle" not in project:
730-
bundle_data = project["data"].get("bundle", {})
731+
bundle_data = project["data"].get("bundle") or {}
731732
prod_bundle = bundle_data.get("production")
732733
staging_bundle = bundle_data.get("staging")
733734
project["bundle"] = {
@@ -736,9 +737,12 @@ def _fill_project_entity_data(self, project: dict[str, Any]) -> None:
736737
}
737738

738739
# Convert 'config' from string to dict if needed
739-
config = project.get("config")
740-
if isinstance(config, str):
741-
project["config"] = json.loads(config)
740+
if "config" in project:
741+
config = project["config"]
742+
if config is None:
743+
project["config"] = {}
744+
elif isinstance(config, str):
745+
project["config"] = json.loads(config)
742746

743747
# Unifiy 'linkTypes' data structure from REST and GraphQL
744748
if "linkTypes" in project:

0 commit comments

Comments
 (0)