danfairs / django-lazysignup

django-lazysignup is a package designed to allow users to interact with a site as if they were authenticated users, but without signing up. At any time, they can convert their temporary user account to a real user account.
BSD 3-Clause "New" or "Revised" License
410 stars 89 forks source link

Use of timezone aware migrations #34

Closed EdwardIII closed 3 years ago

EdwardIII commented 11 years ago

Would it be possible to modify the migration 0002_auto__add_field_lazyuser_created to use django timezone aware datetimes? Currently it produces warnings during tests etc like this one (configured to turn warnings into errors so as to show stacktrace):

FailedDryRun:  ! Error found during dry run of '0002_auto__add_field_lazyuser_created'! Aborting.
Traceback (most recent call last):
  File "/home/edward/python/lib/python2.7/site-packages/south/migration/migrators.py", line 175, in _run_migration
    migration_function()
  File "/home/edward/python/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda>
    return (lambda: direction(orm))
  File "/home/edward/python/lib/python2.7/site-packages/lazysignup/migrations/0002_auto__add_field_lazyuser_created.py", line 14, in forwards
    keep_default=False)
  File "/home/edward/python/lib/python2.7/site-packages/south/db/sqlite3.py", line 31, in add_column
    field.column: self._column_sql_for_create(table_name, name, field, False),
  File "/home/edward/python/lib/python2.7/site-packages/south/db/sqlite3.py", line 189, in _column_sql_for_create
    sql = self.column_sql(table_name, name, field, with_name=False, field_prepared=True)
  File "/home/edward/python/lib/python2.7/site-packages/south/db/generic.py", line 688, in column_sql
    default = field.get_db_prep_save(default, connection=self._get_connection())
  File "/home/edward/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 304, in get_db_prep_save
    prepared=False)
  File "/home/edward/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 835, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/edward/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 827, in get_prep_value
    RuntimeWarning)
RuntimeWarning: DateTimeField received a naive datetime (2013-06-24 15:25:54.034421) while time zone support is active.
danfairs commented 11 years ago

Sounds like a plan. I forget - did timezone handling arrive in Django 1.4? Just trying to think if there are any back-compat concerns.

EdwardIII commented 11 years ago

From what I can see it was introduced in 1.4: New in Django 1.4.

If you need to support further back than that perhaps you could use something like this?

try:
    import django.utils.timezone as my_datetime
except ImportError:
    from datetime import datetime as my_datetime

print my_datetime.now() # You'd need to change all calls to now
danfairs commented 11 years ago

Well - that prompted me to check the lazysignup docs, and they claim it works on 1.2! I think that's definitely wrong. The Travis CI config only tests 1.4 or later. I'm happy to make lazysignup officially 1.4 or later now, so we don't need to worry about conditional imports for this. I should also update the docs...!

EdwardIII commented 11 years ago

Awesome, thanks for looking into this!

barqshasbite commented 10 years ago

Any hope of this being addressed?