Skip to content

Commit

Permalink
hotfix: use variable to deactivate es_handle_save
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Sep 13, 2022
1 parent d9b6947 commit 93b0ed9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 6 additions & 3 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,12 @@ def get_user_authorization(self, user):

# Excluding ROLE_TRANSLATE as it does not correspond to the same role in the client app (connect).
# todo: update this conditional with corresponding role rule
if repo_auth.role < org_auth.role and org_auth.role < RepositoryAuthorization.ROLE_TRANSLATE:
if (
repo_auth.role < org_auth.role
and org_auth.role < RepositoryAuthorization.ROLE_TRANSLATE
):
repo_auth.role = org_auth.role
repo_auth.save(update_fields=['role'])
repo_auth.save(update_fields=["role"])
return repo_auth

def get_absolute_url(self):
Expand Down Expand Up @@ -1271,7 +1274,7 @@ def _relational_requirements_to_train(self):

@property
def requirements_to_train(self):
if settings.USE_ELASTICSEARCH:
if settings.ELASTICSEARCH_EXAMPLES:
return self._elasticsearch_requirements_to_train
else:
return self._relational_requirements_to_train
Expand Down
9 changes: 5 additions & 4 deletions bothub/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@

@app.task(name="es_handle_save")
def handle_save(pk, app_label, model_name):
sender = apps.get_model(app_label, model_name)
instance = sender.objects.get(pk=pk)
registry.update(instance)
registry.update_related(instance)
if settings.USE_ELASTICSEARCH:
sender = apps.get_model(app_label, model_name)
instance = sender.objects.get(pk=pk)
registry.update(instance)
registry.update_related(instance)


@app.task()
Expand Down
2 changes: 2 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
REPOSITORY_EXAMPLE_TEXT_WORDS_LIMIT=(int, 200),
ELASTICSEARCH_DSL=(str, "localhost:9200"),
ELASTICSEARCH_REPOSITORYNLPLOG_INDEX=(str, "ai_repository_classifier_nlplog"),
ELASTICSEARCH_EXAMPLES=(bool, False),
USE_ELASTICSEARCH=(bool, True),
ELASTICSEARCH_REPOSITORYQANLPLOG_INDEX=(str, "ai_repository_qa_nlplog"),
ELASTICSEARCH_REPOSITORYBASICEXAMPLE_INDEX=(str, "ai_repositorybasicexample"),
Expand Down Expand Up @@ -577,6 +578,7 @@
"default": {"hosts": env.str("ELASTICSEARCH_DSL", default="es:9200")}
}

ELASTICSEARCH_EXAMPLES = env.bool("ELASTICSEARCH_EXAMPLES", default=False)
USE_ELASTICSEARCH = env.bool("USE_ELASTICSEARCH", default=True)

ELASTICSEARCH_DSL_INDEX_SETTINGS = {
Expand Down

0 comments on commit 93b0ed9

Please sign in to comment.