spyne icon indicating copy to clipboard operation
spyne copied to clipboard

Contradiction on DateTime.Attributes.as_timezone

Open xavfernandez opened this issue 10 years ago • 4 comments

There seems to be a contradiction between the documentation: https://github.com/arskom/spyne/blob/master/spyne/model/primitive.py#L715-L718 """ When this is None and a datetime with tzinfo=None comes in, it's converted to spyne.LOCAL_TZ which defaults to pytz.utc. You can use tzlocal <https://pypi.python.org/pypi/tzlocal>_ to set it to local time right after import spyne."""

and the code: https://github.com/arskom/spyne/blob/master/spyne/protocol/_base.py#L631-L637 if cls.Attributes.as_timezone is None, the datetime stays naive and spyne.LOCAL_TZ isn't used.

Not sure if you want to fix the documentation or the code but I would be more in favor to the code :)

xavfernandez avatar Nov 07 '14 14:11 xavfernandez

The docs are a bit unclear. LOCAL_TZ is only forced for validation

plq avatar Nov 09 '14 16:11 plq

Too bad ! Always switching to timezone aware datetime (by defaulting to spyne.LOCAL_TZ=UTC) seemed like a good idea to me.

xavfernandez avatar Nov 10 '14 17:11 xavfernandez

Spyne is as minimally opinionated as possible. Running a timezone-free app should be as easy running one with all-utc timezones. You really need to be a Python expert to properly understand some aspects of Spyne -- this story with time zones is a good example.

But neurons, which is a new project of mine which gets most of my (open source) time these days, it the opposite. I'm leaving as little room as possible to the user.

Those said, you can use astz to force any date time value to a time zone. You can even override Spyne's own DateTime with a datetime that has an astz value

plq avatar Nov 10 '14 21:11 plq

I understand your point but I don't think allowing timezone-free datetime really helps the user... At least, the default should definitely be timezone aware.

xavfernandez avatar Nov 11 '14 12:11 xavfernandez