nitely / Spirit

Spirit is a modern Python based forum built on top of Django framework
http://spirit.readthedocs.io
MIT License
1.16k stars 334 forks source link

Server error when USE_TZ = False #316

Open sureshvv opened 1 year ago

sureshvv commented 1 year ago
  File "django42/lib/python3.8/site-packages/spirit/user/views.py", line 32, in update
    form = UserProfileForm(
  File "django42/lib/python3.8/site-packages/spirit/user/forms.py", line 103, in __init__
    now = timezone.localtime(timezone.now())
  File "django42/lib/python3.8/site-packages/django/utils/timezone.py", line 218, in localtime
    raise ValueError("localtime() cannot be applied to a naive datetime")

Exception Type: ValueError at /spirit/user/
Exception Value: localtime() cannot be applied to a naive datetime
Raised during: spirit.user.views.update

Changing forms.py line 103 to

now = timezone.now()

seems to have "fixed" it.

nitely commented 1 year ago

CI runs on Django 4.2 and Python 3.8. Maybe it's a config issue, the default is USE_TZ = True and tz disabled is not supported.

nitely commented 1 year ago

https://github.com/django/django/blob/main/django/utils/timezone.py#L204

It looks like your config has USE_TZ set to false

sureshvv commented 1 year ago

I see I have USE_TZ commented out in my settings. It may be impacting another app that I am using.

sureshvv commented 1 year ago

Is there a way in django where you can extend settings.py from each installed app? It seems some of my problems are to do with the fact that I am installing Spirit on an existing site - so I have to retrofit all the changes onto my original settings.py. A mechanism to add to the settings.py from each installed app (with warnings for incompatibility) will improve the overall experience.

Is djconfig an attempt at doing this?

nitely commented 1 year ago

Settings.py module is loaded before all apps. By the time an app is loaded all settings have been used by Django and changing them won't do anything in most cases. So, you need manually merge your existing settings.py file with Spirit's base.py file, idk about other way.

Djconfig is an app to store and retrieve settings from a data base, so it can be donde from the website and no server restart is needed.

For app static settings there is https://github.com/nitely/django-app-defaults but Spirit already does something like that with all the ST_ settings and it does not solve the need to modify the Django specific settings.

On Mon., Jul. 31, 2023, 1:14 p.m. sureshvv, @.***> wrote:

Is there a way in django where you can extend settings.py from each installed app? It seems some of my problems are to do with the fact that I am installing Spirit on an existing site - so I gave to retrofit all the changes onto my original settings.py. A mechanism to add to the settings.py from each installed app (with warnings for incompatibility) will improve the overall experience.

Is djconfig an attempt at doing this?

— Reply to this email directly, view it on GitHub https://github.com/nitely/Spirit/issues/316#issuecomment-1658706558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM6L44CBGXZTXAAWXWWCNDXS7KWPANCNFSM6AAAAAA25FWYKY . You are receiving this because you commented.Message ID: @.***>

nitely commented 1 year ago

Leaving this open as Spirit should either work with USE_TZ = False or add a validator to core app to check it's True.

nitely commented 1 year ago

Also created an issue to improve the settings validations #318