Random "Image does not have valid dimensions" errors on files import
When running file imports in prod, uploading an image and immediately using it to create an element causes an error:
[INFO] Fetching images for -088.png
[INFO] Creating 1 elements
[INFO] Uploading image f80e40b3-7597-4f64-ada9-04e368fe7816
Traceback (most recent call last):
[snip]
File "/usr/local/lib/python3.6/site-packages/arkindex_tasks/import_files/base.py", line 123, in save_elements
'parent': self.folder['id'],
[snip]
apistar.exceptions.ErrorResponse: {'image': ['This image does not have valid dimensions.']}
This error is triggered by this line of code, ensuring elements will not be created on images with dimensions of 0 pixels (which would cause errors with polygon reordering). The check constraints on the Image model require non-zero dimensions for checked
images; since the image upload ends with running the image check, the file import would not proceed with creating an element if the check failed. The image mentioned in the above logs indeed is checked and has valid dimensions.
This issue does not seem to be reproducible in preprod or in dev environments. This could be linked to the new Postgres cluster: using an image to create element right after setting its dimensions could lead to a write on the master not being synchronized (or some type of cache not being invalidated) yet on the replicas, causing subsequent reads to not have the updated data and causing this error. This theory could also apply to the following issues:
-
frontend#266 (closed), in which starting a DataImport causes the creation of a
Workflow
instance but is not set; the frontend does not check for this error and this leads toNot found
errors when polling the status of the newly started import. Refreshing the page later fixes the issue. -
frontend#271 (closed), in which logging in causes the creation or update of a session in the
django_session
table, but subsequent API requests return HTTP 403 due to the users not being logged in. Refreshing the page later fixes the issue.