Skip to content
Snippets Groups Projects
Commit c0085e3b authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Reload known ML classes when a 400 is received on creation

parent 74b734fb
No related branches found
No related tags found
No related merge requests found
Pipeline #77996 passed
......@@ -8,6 +8,7 @@ import uuid
from enum import Enum
from pathlib import Path
import apistar
import gnupg
import yaml
from apistar.exceptions import ErrorResponse
......@@ -294,11 +295,23 @@ class ElementsWorker(BaseWorker):
ml_class_id = self.classes[corpus_id].get(ml_class)
if ml_class_id is None:
logger.info(f"Creating ML class {ml_class} on corpus {corpus_id}")
response = self.api_client.request(
"CreateMLClass", id=corpus_id, body={"name": ml_class}
)
try:
response = self.api_client.request(
"CreateMLClass", id=corpus_id, body={"name": ml_class}
)
logger.debug(f"Created ML class {response['id']}")
except apistar.exceptions.ErrorResponse as e:
# Only reload for 400 errors
if e.status_code != 400:
raise
# Reload and make sure we have the class
self.load_corpus_classes(corpus_id)
assert (
ml_class in self.classes[corpus_id]
), "Missing class {ml_class} even after reloading"
ml_class_id = self.classes[corpus_id][ml_class] = response["id"]
logger.debug(f"Created ML class {ml_class_id}")
return ml_class_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment