Skip to content

Commit

Permalink
fix: rename DISABLE_PRODUCT_CHECK into ENABLE_PRODUCT_CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Apr 12, 2023
1 parent 6d62da6 commit 36f5036
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ TF_MODELS_DIR=./tf_models
TRITON_MODELS_DIR=./models

# Disable product check locally to be able to easily test image import
DISABLE_PRODUCT_CHECK=1
ENABLE_PRODUCT_CHECK=1
2 changes: 1 addition & 1 deletion doc/how-to-guides/test-and-debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Write test cases every time you write a new feature, to test a feature or to und
There are even cases where automated tests are your only chance to test you code. For example: when you write code to post notifications on Slack channel you can only test them by writing a unit test case.

There are instances when Robotoff tries to connect to MongoDB via Open Food Facts server. To disable this
feature (this is disabled by default on local environments), set `DISABLE_PRODUCT_CHECK=1` in your `.env`.
feature (this is disabled by default on local environments), set `ENABLE_PRODUCT_CHECK=0` in your `.env`.

# Debugging guide

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ x-robotoff-base-env:
ELASTIC_USER:
TF_SERVING_HOST:
TRITON_HOST:
DISABLE_PRODUCT_CHECK:
ENABLE_PRODUCT_CHECK:
IN_DOCKER_CONTAINER:


Expand Down
6 changes: 5 additions & 1 deletion robotoff/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def save_image(
is None
:param images: image dict mapping image ID to image metadata, as returned
by Product Opener API, is None if product validity check is disabled
(`DISABLE_PRODUCT_CHECK=True`)
(`ENABLE_PRODUCT_CHECK=False`)
:return: this function return either:
- the ImageModel of the image if it already exist in DB
- None if the image is non raw (non-digit image ID), if it's not
Expand Down Expand Up @@ -74,6 +74,10 @@ def save_image(
uploaded_at = datetime.datetime.utcfromtimestamp(uploaded_t)
else:
uploaded_at = None
# DB product check is disabled which means we shouldn't rely on having
# a MongoDB instance running. As image size information is stored in
# MongoDB (in the `images` field), we download the image to know the image
# size
logger.info("DB Product check disabled, downloading image to get image size")
image = get_image_from_url(image_url, error_raise=False, session=http_session)

Expand Down
6 changes: 3 additions & 3 deletions robotoff/insights/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ def generate_insights(
product = product_store[product_id]
references = get_existing_insight(cls.get_type(), product_id)

# If `DISABLE_PRODUCT_CHECK` is False (default, production settings), we
# If `ENABLE_PRODUCT_CHECK` is True (default, production settings), we
# stop the import process and delete all associated insights
if product is None and not settings.DISABLE_PRODUCT_CHECK:
if product is None and settings.ENABLE_PRODUCT_CHECK:
logger.info("%s not found in DB, deleting existing insights", product_id)
return [], [], references

Expand Down Expand Up @@ -1416,7 +1416,7 @@ def import_predictions(
for p in predictions
if (
# If product validity check is disable, all predictions are valid
settings.DISABLE_PRODUCT_CHECK
not settings.ENABLE_PRODUCT_CHECK
or is_valid_product_prediction(p, product_store[ProductIdentifier(p.barcode, server_type)]) # type: ignore
)
]
Expand Down
2 changes: 1 addition & 1 deletion robotoff/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,4 @@ def init_sentry(integrations: Optional[list[Integration]] = None):
# - when importing a new image through a webhook call (in robotoff.workers.tasks.import_image)
# This is useful when testing locally, as we don't need the product to be in MongoDB to import
# an image and generate insights.
DISABLE_PRODUCT_CHECK = bool(int(os.environ.get("DISABLE_PRODUCT_CHECK", 0)))
ENABLE_PRODUCT_CHECK = bool(int(os.environ.get("ENABLE_PRODUCT_CHECK", 1)))
4 changes: 2 additions & 2 deletions robotoff/workers/tasks/import_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_import_image_job(product_id: ProductIdentifier, image_url: str, ocr_url:
logger.info("Running `import_image` for %s, image %s", product_id, image_url)
source_image = get_source_from_url(image_url)
product = get_product_store(product_id.server_type)[product_id]
if product is None and not settings.DISABLE_PRODUCT_CHECK:
if product is None and settings.ENABLE_PRODUCT_CHECK:
logger.info(
"%s does not exist during image import (%s)",
product_id,
Expand Down Expand Up @@ -165,7 +165,7 @@ def save_image_job(batch: list[tuple[ProductIdentifier, str]], server_type: Serv
with db.connection_context():
for product_id, source_image in batch:
product = product_store[product_id]
if product is None and not settings.DISABLE_PRODUCT_CHECK:
if product is None and settings.ENABLE_PRODUCT_CHECK:
continue

with db.atomic():
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@pytest.fixture(autouse=True)
def set_global_settings(mocker):
mocker.patch("robotoff.settings.DISABLE_PRODUCT_CHECK", False)
mocker.patch("robotoff.settings.ENABLE_PRODUCT_CHECK", True)


@pytest.fixture(scope="session", autouse=True)
Expand Down

0 comments on commit 36f5036

Please sign in to comment.