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_) \
                       '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__
>>> utc = pytz.timezone('UTC')
>>> la = pytz.timezone('America/Los_Angeles')
>>> isinstance(utc, pytz.tzinfo.BaseTzInfo)
>>> isinstance(la, pytz.tzinfo.BaseTzInfo)

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 
    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 
<https://github.com/stub42/pytz/issues/10>), or if this is a problem on the 
TimezoneType side. Or am I missing something here?


SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


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.

Reply via email to