django-seed icon indicating copy to clipboard operation
django-seed copied to clipboard

Seeding datetime objects fails due to Django 5.0 deprecating the `is_dst` argument to `timezone.make_aware`

Open offbyone opened this issue 1 year ago • 6 comments

The is_dst argument to make_aware() is deprecated as of Django 5.0: https://docs.djangoproject.com/en/dev/internals/deprecation/#deprecation-removed-in-5-0

Running manage.py seed on an application with DateTimeField in the models results in this:

/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/db/models/fields/__init__.py:1654: RuntimeWarning: DateTimeField ElectionState.valid_from received a naive datetime (2023-12-11 07:14:28.937317) while time zone support is active.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/offby1/projects/worldcon/nomnom/manage.py", line 22, in <module>
    main()
  File "/Users/offby1/projects/worldcon/nomnom/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 639, in handle
    app_output = self.handle_app_config(app_config, **options)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/management/commands/seed.py", line 63, in handle_app_config
    generated = seeder.execute()
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/seeder.py", line 250, in execute
    executed_entity = entity.execute(using, inserted_entities)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/seeder.py", line 157, in execute
    faker_data = {
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/seeder.py", line 158, in <dictcomp>
    field: format_field(field_format, inserted_entities)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/seeder.py", line 144, in format_field
    return format(inserted_entities)
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/guessers.py", line 120, in <lambda>
    return lambda x: _timezone_format(faker.date_time())
  File "/Users/offby1/projects/worldcon/nomnom/.venv/lib/python3.10/site-packages/django_seed/guessers.py", line 21, in _timezone_format
    return timezone.make_aware(value, timezone.get_current_timezone(), is_dst=False)
TypeError: make_aware() got an unexpected keyword argument 'is_dst'

offbyone avatar Dec 11 '23 07:12 offbyone

I was trying to create a seed to models with DateTimeField and encountered the same issue . Using Django==5.0.1 and django-seed==0.3.1

mantertius avatar Feb 17 '24 23:02 mantertius

Is there any fix around this?

Omkar-Jawalkar avatar Apr 29 '24 04:04 Omkar-Jawalkar

Is there any fix around this?

in the settings.py set USE_TZ = False

the error occurs when it tries to generates a timezone aware datetime if the 'USE_TZ' setting is enabled

salimbyte avatar May 31 '24 09:05 salimbyte

in the project settings.py set USE_TZ = False and also install django==5.0.1 version (django-seed=0.3.1)

krv006 avatar Oct 25 '24 12:10 krv006

Does anyone have a solution for projects which require USE_TZ=True?

ethagnawl avatar Feb 04 '25 04:02 ethagnawl

This seems to fix it https://github.com/Brobin/django-seed/pull/120

daninus14 avatar Mar 05 '25 17:03 daninus14