#36384 closed Cleanup/optimization (worksforme)
update_dimension_fields blocks getting model instances from the database when the external storage has issues
Reported by: | Gerben Morsink | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Gerben Morsink | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
It seems when a height_field or width_field are given, the update_dimension_fields is always called on initialization of the model instance. Thereby always doing a call to an external database if those fields are empty.
This might seem obvious, but it means that when and external storage is down, it is not possible anymore to get this Model instance anymore.
For example with S3 issue it might raise:
ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
even when I simply want to get the object without the width and height, like here:
UserAvatar.objects.get(user=user).only('id')
This is in my opinion an unexpected consequence of adding the height_field and width_field to an ImageField.
What do you think, should width and height be lazily loaded somehow?
Change History (2)
comment:1 by , 4 months ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:2 by , 4 months ago
Description: | modified (diff) |
---|---|
Easy pickings: | unset |
The quote code snippet is checking whether the ImageField
has height/width fields specified, so that's not the code that will raise an exception. The report certainly seems plausible, even if it's unclear how the situation could be improved. It might be the S3 storage backend rather than Django that should be resilient to network failure.
I cannot replicate this. Update dimension fields has logic to handle this, and from my testing this works
Can you provide a test or a way to replicate this behavior?