Skip to content

Fix attempting to access deferred fields in stdimage file descriptor #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdimage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def set_variations(self, instance=None, **kwargs):

:param instance: FileField
"""
if getattr(instance, self.name):
deferred_field = self.name in instance.get_deferred_fields()
if not deferred_field and getattr(instance, self.name):
field = getattr(instance, self.name)
if field._committed:
for name, variation in list(self.variations.items()):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_custom_render_variations(self, db):
assert instance.image.thumbnail.width == 100
assert instance.image.thumbnail.height == 100

def test_defer(self, db, django_assert_num_queries):
"""Test that set_variations doesn't attempt to use field data
when the field is deferred, which would result
in another query being executed implicitly.
"""
instance = SimpleModel.objects.create(image=self.fixtures['100.gif'])
with django_assert_num_queries(1):
SimpleModel.objects.only('pk').get(pk=instance.pk)


class TestUtils(TestStdImage):
"""Tests Utils"""
Expand Down