@@ -61,7 +61,9 @@ def list_assets(
6161 "LLM_STATIC" ,
6262 "GEOSPATIAL" ,
6363 }:
64- fetch_annotations = not (has_labels_url or has_latest_label_url )
64+ fetch_annotations = ("labels.jsonResponse" in fields and not has_labels_url ) or (
65+ "latestLabel.jsonResponse" in fields and not has_latest_label_url
66+ )
6567 yield from self .list_assets_split (
6668 filters , fields , options , project_info , fetch_annotations
6769 )
@@ -110,7 +112,11 @@ def list_assets_split(
110112 { inner_annotation_fragment }
111113 }}
112114 """
113- static_fragments = {"labels" : annotation_fragment , "latestLabel" : annotation_fragment }
115+ static_fragments = {}
116+ if "labels.jsonResponse" in fields and "labels.jsonResponseUrl" not in fields :
117+ static_fragments ["labels" ] = annotation_fragment
118+ if "latestLabel.jsonResponse" in fields and "latestLabel.jsonResponseUrl" not in fields :
119+ static_fragments ["latestLabel" ] = annotation_fragment
114120
115121 required_fields = {"content" , "jsonContent" , "resolution.width" , "resolution.height" }
116122 fields = list (fields )
@@ -133,24 +139,33 @@ def list_assets_split(
133139 json_interface = project_info ["jsonInterface" ],
134140 project_input_type = project_info ["inputType" ],
135141 )
136- is_requesting_annotations = any ("annotations." in element for element in fields )
137- for asset in assets_gen :
138- if "latestLabel.jsonResponse" in fields and asset .get ("latestLabel" ):
139- converter .patch_label_json_response (
140- asset , asset ["latestLabel" ], asset ["latestLabel" ]["annotations" ]
141- )
142- if not is_requesting_annotations :
143- asset ["latestLabel" ].pop ("annotations" )
144-
145- if "labels.jsonResponse" in fields :
146- for label in asset .get ("labels" , []):
147- converter .patch_label_json_response (asset , label , label ["annotations" ])
148- if not is_requesting_annotations :
149- label .pop ("annotations" )
150- yield asset
142+ yield from self ._reconstruct_json_responses (assets_gen , fields , converter )
151143 else :
152144 yield from assets_gen
153145
146+ def _reconstruct_json_responses (
147+ self ,
148+ assets_gen : Generator [dict , None , None ],
149+ fields : ListOrTuple [str ],
150+ converter : AnnotationsToJsonResponseConverter ,
151+ ) -> Generator [dict , None , None ]:
152+ """Reconstruct jsonResponse from annotations, then remove annotations from the result."""
153+ is_requesting_annotations = any ("annotations." in element for element in fields )
154+ for asset in assets_gen :
155+ if "latestLabel.jsonResponse" in fields and asset .get ("latestLabel" ):
156+ converter .patch_label_json_response (
157+ asset , asset ["latestLabel" ], asset ["latestLabel" ]["annotations" ]
158+ )
159+ if not is_requesting_annotations :
160+ asset ["latestLabel" ].pop ("annotations" )
161+
162+ if "labels.jsonResponse" in fields :
163+ for label in asset .get ("labels" , []):
164+ converter .patch_label_json_response (asset , label , label ["annotations" ])
165+ if not is_requesting_annotations :
166+ label .pop ("annotations" )
167+ yield asset
168+
154169 def count_assets (self , filters : AssetFilters ) -> int :
155170 """Send a GraphQL request calling countIssues resolver."""
156171 where = asset_where_mapper (filters )
0 commit comments