Skip to content
Snippets Groups Projects

Reload known ML classes when a 400 is received on creation

Merged Bastien Abadie requested to merge fix-24 into master
1 file
+ 17
4
Compare changes
  • Side-by-side
  • Inline
+ 17
4
@@ -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
@@ -296,11 +297,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
Loading