Django 1.10:S3上的django-storages错误:没有天真的日期时间(已经设置了tzinfo)

时间:2016-08-30 17:40:45

标签: python django boto3 django-storage

自升级到Django 1.10以来,我开始收到错误消息。我使用django-storages==1.5.0boto3==1.4.0在Python 3.5上运行Django 1.10。

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/management/base.py", line 305, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/management/base.py", line 356, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
    collected = self.collect()
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 337, in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 258, in delete_file
    target_last_modified = self.storage.get_modified_time(prefixed_path)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/files/storage.py", line 231, in get_modified_time
    return _possibly_make_aware(dt)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/core/files/storage.py", line 243, in _possibly_make_aware
    return timezone.make_aware(dt, tz).astimezone(timezone.utc)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/django/utils/timezone.py", line 368, in make_aware
    return timezone.localize(value, is_dst=is_dst)
  File "/home/vagrant/.virtualenvs/wrds-classroom/lib/python3.5/site-packages/pytz/tzinfo.py", line 304, in localize
    raise ValueError('Not naive datetime (tzinfo is already set)')
ValueError: Not naive datetime (tzinfo is already set)

USE_TZ更改为False会更改错误,但我仍然不确定导致错误的原因(这是Django代码库中的新区域):

TypeError: can't compare offset-naive and offset-aware datetimes

知道原因是什么吗?

1 个答案:

答案 0 :(得分:1)

<强>更新

我正在更新自己的答案,因为此拉取请求现已合并。要解决此问题,只需在1.5.1requirements.txt命令中使用版本pip install

django-storages==1.5.1

有关背景的日期回答:

我已经找到了一个临时解决方案,可以导致永久修复。

经过一番调查后,一位朋友发现了他们认为可能与之相关的公关:https://github.com/jschneier/django-storages/pull/181

我注意到拉取请求的日期是我运行的最新django-storages版本(1.5.0)后两天。在我的requirements.txt中,我只是这样做,指向提交的哈希:

#django-storages==1.5.0
git+https://github.com/jschneier/django-storages.git#5f280571ee1ae93ee66ed805b53b08bfe5ab9f0c
boto3==1.4.0

然后,pip install --upgrade -r requirements.txt并再次运行collectstatic,不再出错!我猜测此修复程序将包含在1.5.1版本中,此时我只需再次更改requirements.txt