|
16 | 16 | limitations under the License.
|
17 | 17 | -----------------------------------------------------------------
|
18 | 18 | """
|
19 |
| - |
| 19 | +from contextlib import suppress |
20 | 20 | from typing import ClassVar, Optional, Union
|
21 | 21 |
|
22 | 22 | from app.translator.const import DEFAULT_VALUE_TYPE
|
@@ -229,23 +229,26 @@ def generate_from_tokenized_query_container(self, query_container: TokenizedQuer
|
229 | 229 | errors = []
|
230 | 230 | source_mappings = self._get_source_mappings(query_container.meta_info.source_mapping_ids)
|
231 | 231 |
|
232 |
| - for source_mapping in source_mappings: |
| 232 | + last_mapping_index = len(source_mappings) - 1 |
| 233 | + for index, source_mapping in enumerate(source_mappings): |
233 | 234 | try:
|
234 | 235 | finalized_query = self._generate_from_tokenized_query_container_by_source_mapping(
|
235 | 236 | query_container, source_mapping
|
236 | 237 | )
|
| 238 | + if return_only_first_query_ctx_var.get() is True: |
| 239 | + return finalized_query |
| 240 | + queries_map[source_mapping.source_id] = finalized_query |
237 | 241 | except StrictPlatformException as err:
|
238 |
| - if source_mapping.source_id != DEFAULT_MAPPING_NAME: |
239 |
| - errors.append(err) |
| 242 | + errors.append(err) |
| 243 | + if index != last_mapping_index or source_mapping.source_id == DEFAULT_MAPPING_NAME or queries_map: |
240 | 244 | continue
|
241 | 245 |
|
242 |
| - finalized_query = self._generate_from_tokenized_query_container_by_source_mapping( |
243 |
| - query_container, self.mappings.get_source_mapping(DEFAULT_MAPPING_NAME) |
244 |
| - ) |
| 246 | + with suppress(StrictPlatformException): |
| 247 | + finalized_query = self._generate_from_tokenized_query_container_by_source_mapping( |
| 248 | + query_container, self.mappings.get_source_mapping(DEFAULT_MAPPING_NAME) |
| 249 | + ) |
| 250 | + queries_map[source_mapping.source_id] = finalized_query |
245 | 251 |
|
246 |
| - if return_only_first_query_ctx_var.get() is True: |
247 |
| - return finalized_query |
248 |
| - queries_map[source_mapping.source_id] = finalized_query |
249 | 252 | if not queries_map and errors:
|
250 | 253 | raise errors[0]
|
251 | 254 | return self.finalize(queries_map)
|
0 commit comments