Re: [sqlalchemy] sqlalchemy_utils.TimezoneType problems with pytz and UTC

2018-03-08 Thread jens . troeger
Thank you Mike! I also filed an issue with 
sqlalchemy_utils: https://github.com/kvesteri/sqlalchemy-utils/issues/315


On Thursday, March 8, 2018 at 11:27:20 PM UTC+10, Mike Bayer wrote:
>
> just FYI I don't do sqlalchemy-utils though other people here may have 
> insight into your question. 
>
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] sqlalchemy_utils.TimezoneType problems with pytz and UTC

2018-03-08 Thread Mike Bayer
just FYI I don't do sqlalchemy-utils though other people here may have
insight into your question.

On Wed, Mar 7, 2018 at 9:24 PM,   wrote:
> Hi,
>
> I just noticed an oddity using the TimezoneType as a column type. Suppose
> the following statement:
>
> conn.execute(t_user.update() \
>.where(t_user.c.id == id_) \
>.values({
>'timezone': pytz.timezone(tzname),
>}))
>
> then tzname="America/Los_Angeles" works, but tzname="UTC" does not. What
> happens is that the _coerce() method contains a type check which has
> different results for the two:
>
 import pytz
 pytz.__version__
> '2018.3'
 utc = pytz.timezone('UTC')
 la = pytz.timezone('America/Los_Angeles')
 isinstance(utc, pytz.tzinfo.BaseTzInfo)
> False
 isinstance(la, pytz.tzinfo.BaseTzInfo)
> True
>
> Because of that, _coerce() attempts to coerce/convert the utc timezone
> object and fails in this line of code:
>
>   File "/…/lib/python3.5/site-packages/sqlalchemy/sql/type_api.py", line
> 1156, in process
> return impl_processor(process_param(value, dialect))
>   File "/…/lib/python3.5/site-packages/sqlalchemy_utils/types/timezone.py",
> line 83, in process_bind_param
> return self._from(self._coerce(value)) if value else None
>   File "/…/lib/python3.5/site-packages/sqlalchemy_utils/types/timezone.py",
> line 76, in _coerce
> obj = self._to(value)
>   File "/…/lib/python3.5/site-packages/pytz/__init__.py", line 162, in
> timezone
> if zone.upper() == 'UTC':
> AttributeError: 'UTC' object has no attribute 'upper'
>
> I am not sure if the above difference with isinstance() is intended or a bug
> on the pytz side (I filed a question/issue here), or if this is a problem on
> the TimezoneType side. Or am I missing something here?
>
> Thanks!
> Jens
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] sqlalchemy_utils.TimezoneType problems with pytz and UTC

2018-03-07 Thread jens . troeger
Hi,

I just noticed an oddity using the TimezoneType as a column type. Suppose 
the following statement:

conn.execute(t_user.update() \
   .where(t_user.c.id == id_) \
   .values({
   'timezone': pytz.timezone(tzname),
   }))

then tzname="America/Los_Angeles" works, but tzname="UTC" does not. What 
happens is that the _coerce() method 

 
contains a type check which has different results for the two:

>>> import pytz
>>> pytz.__version__
'2018.3'
>>> utc = pytz.timezone('UTC')
>>> la = pytz.timezone('America/Los_Angeles')
>>> isinstance(utc, pytz.tzinfo.BaseTzInfo)
False
>>> isinstance(la, pytz.tzinfo.BaseTzInfo)
True

Because of that, _coerce() attempts to coerce/convert the utc timezone 
object and fails in this line of code 
:

  File "/…/lib/python3.5/site-packages/sqlalchemy/sql/type_api.py", line 
1156, in process
return impl_processor(process_param(value, dialect))
  File "/…/lib/python3.5/site-packages/sqlalchemy_utils/types/timezone.py", 
line 83, in process_bind_param
return self._from(self._coerce(value)) if value else None
  File "/…/lib/python3.5/site-packages/sqlalchemy_utils/types/timezone.py", 
line 76, in _coerce
obj = self._to(value)
  File "/…/lib/python3.5/site-packages/pytz/__init__.py", line 162, in 
timezone
if zone.upper() == 'UTC':
AttributeError: 'UTC' object has no attribute 'upper'

I am not sure if the above difference with isinstance() is intended or a 
bug on the pytz side (I filed a question/issue here 
), or if this is a problem on the 
TimezoneType side. Or am I missing something here?

Thanks!
Jens

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.