Skip to content

Commit

Permalink
Fix Django 1.7 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
strayer committed Apr 21, 2016
1 parent c2cd93c commit 92e4bb8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion django_gcloud_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
from tempfile import SpooledTemporaryFile

import django
from django.conf import settings
from django.core.exceptions import SuspiciousFileOperation
from django.core.files.base import File
Expand All @@ -17,6 +18,8 @@
from gcloud.exceptions import NotFound
from gcloud.storage.bucket import Bucket

DJANGO_17 = django.get_version().startswith('1.7.')

try:
# For Python 3.0 and later
from urllib import parse as urlparse
Expand Down Expand Up @@ -78,7 +81,13 @@ def __init__(self, blob, maxsize=1000):
def _update_blob(self):
# Specify explicit size to avoid problems with not yet spooled temporary files
# Djangos File.size property already knows how to handle cases like this
self._blob.upload_from_file(self._tmpfile, size=self.size, rewind=True)

if DJANGO_17 and self._tmpfile.name is None: # Django bug #22307
size = self._tmpfile.tell()
else:
size = self.size

self._blob.upload_from_file(self._tmpfile, size=size, rewind=True)

def write(self, content):
self._dirty = True
Expand Down

0 comments on commit 92e4bb8

Please sign in to comment.