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, <[email protected]> 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
