emencia / django-blog-lotus

A weblog application with Django.
https://django-blog-lotus.readthedocs.io/
MIT License
5 stars 1 forks source link

Concern about timezone #72

Open sveetch opened 7 months ago

sveetch commented 7 months ago

Describe the bug DjangoRestFramework apply current timezone to the datetime values in serializer fields. Concretely it applies the timezone defined in settings.TIMEZONE to datetimes in serializer payload.

Environment Describe your environment:

To Reproduce

However from serializers tests it seems that ArticleSerializer.publish_datetime() has no timezone applied from output serializer, this is because we use a SerializerMethodField for it so we don't have the serializers.DateTimeField behavior.

Expected behavior All date should behave the same. We can apply the timezone in ArticleSerializer.publish_datetime() but it needs to copy the DRF one, that seem to be conditionned to settings.USE_TZ value.

Additional context This should be a concern only in API, but view/templatetag code have to be inspected to check if they use something like isoformat() formatting which would transform date object in string, that Django would not be able to apply current timezone.

sveetch commented 7 months ago

A change for this timezone problem has been made in a test for Category serializer after adding a new datetime field to the model:

https://github.com/emencia/django-blog-lotus/commit/d16d285c811d27339c9134103e60aa37b711db36#diff-12a026764140d30c3977c975c7c95b036237cf17d4bb6deac5b56b667938fbcfR159

sveetch commented 7 months ago

It seems only Article publish_datetime serializer field is missing the timezone. There is also Article publish_time but i'm not sure it would need the timezone and maybe it is not useful to have the divided publish date and time in payload ?