I am facing a really strange behavior with my Photo
model, containing a ImageField
.
When I execute the following piece of code:
photos = Photo.objects.all()
for p in photos:
print p.id
I get this error after Django displayed about 36680 ids :
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/me/Sites/django/mysite/forum/views.py", line 286, in photos_search
for p in photos:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 139, in _result_iter
self._fill_cache()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 941, in _fill_cache
self._result_cache.append(next(self._iter))
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 327, in iterator
obj = model(*row_data)
File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 417, in __init__
signals.post_init.send(sender=self.__class__, instance=self)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 379, in update_dimension_fields
width = file.width
File "/Library/Python/2.7/site-packages/django/core/files/images.py", line 15, in _get_width
return self._get_image_dimensions()[0]
File "/Library/Python/2.7/site-packages/django/core/files/images.py", line 25, in _get_image_dimensions
self.open()
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 76, in open
self.file.open(mode)
File "/Library/Python/2.7/site-packages/django/db/models/fields/files.py", line 46, in _get_file
self._file = self.storage.open(self.name, 'rb')
File "/Library/Python/2.7/site-packages/django/core/files/storage.py", line 36, in open
return self._open(name, mode)
File "/Library/Python/2.7/site-packages/django/core/files/storage.py", line 159, in _open
return File(open(self.path(name), mode))
IOError: [Errno 2] No such file or directory: u'<path_to_my_photo>'
Weirder, when I start at id=35000, then it crashes the same way, but, after having displayed 36668 ids...
photos = Photo.objects.filter(id__gte=35000)
for p in photos:
print p.id
When I individually query the 36668th or the 36680th object, everything seems OK.
I can't understand why Django tries to get "get_image_dimensions
" when I just read the photos list ?
Any idea ?