No special requirement for pymysql on my end, installed mysqlclient and now 
the test passes.

Thanks for your help!

On Sunday, July 24, 2016 at 5:09:34 PM UTC-4, Mike Bayer wrote:
>
> this mostly appears to be a pymysql issue (string values should be 
> decoded, mysqlclient acts correctly) so I've reported it at 
>
> https://github.com/PyMySQL/PyMySQL/issues/488 
>
> I'd install mysqlclient for now.  Hopefully pymysql can respond if 
> they'll fix this in time for SQLA 1.1 final.   Tracking it for 
> SQLAlchemy at 
>
> https://bitbucket.org/zzzeek/sqlalchemy/issues/3754/mysql-json-not-handled-by-drivers-in-py3.
>  
>
>     There are ways we can adjust on our end but those would be 
> disruptive if pymysql changes their behavior, which is likely.   There 
> are also ways you can use a workaround type if you absolutely need the 
> combination of SQLA 1.1 beta + pymysql + Py3k + MySQL native JSON (just 
> copy the JSON class from sqlalchemy/dialects/mysql/json.py and add a 
> decode() to result_processor). 
>
>
>
> On 07/23/2016 03:38 PM, Eric Wittle wrote: 
> > I'm trying to include a JSON field in a table with mysql 5.7.12 and 
> > sqlalchemy 1.1b2. I've successfully inserted JSON into the database, but 
> > when I load the record containing the JSON, I get the TypeError shown in 
> > the subject. 
> > 
> > The database was created with charset utf8, and the connect string 
> > specifies utf8mb4, and I'm using pymsql to connect. 
> > 
> > The relevant data model code: 
> > 
> > | 
> > classPerson(Base): 
> >     __tablename__ ='Person' 
> >     __table_args__ ={'mysql_charset':'utf8'} 
> >     id =Column(Integer,primary_key=True) 
> >     other_data =Column(JSON) 
> > 
> >     defget(self,key): 
> >         if(self.other_data andself.other_data[key]): 
> >             returnself.other_data[key] 
> >         else: 
> >             returnundefined 
> > 
> >     defset(self,key,value): 
> >         if(self.other_data): 
> >             self.other_data.data[key]=value 
> >         else: 
> >             self.other_data ={} 
> >             self.other_data[key]=value 
> > 
> > | 
> > 
> > The nosetest that is raising the error: 
> > 
> > | 
> > deftest_GetPersonExtraValue(): 
> >     session =DBSession() 
> >     logger.debug("About to query for p1") 
> >     p1 =session.query(Person).get(1) 
> >     logger.debug("p1.first_name = "+p1.first_name) 
> >     assertp1.get('favorite_color')=='red' 
> > 
> > 
> > defsetup_data(): 
> >     session =DBSession() 
> >     p1 =Person(id=1,first_name='Eric',last_name='Wittle', 
> >                 full_name='Eric L. Wittle',email='er...@wittle.net 
> <javascript:>') 
> >     p1.set('favorite_color','red') 
> >     session.add(p1) 
> >     session.commit() 
> > 
> > | 
> > 
> > The state of the Person table after the nosetest 
> > mysql> select id, other_data from Person; 
> > 
> > mysql> select id, other_data from Person; 
> > 
> > +----+---------------------------+ 
> > 
> > | id | other_data                | 
> > 
> > +----+---------------------------+ 
> > 
> > |  1 | {"favorite_color": "red"} | 
> > 
> > +----+---------------------------+ 
> > 
> > 1 row in set (0.00 sec) 
> > 
> > 
> > And finally the stack trace from the test with the error: 
> > 
> > ====================================================================== 
> > ERROR: server.tests.test_data_model.test_GetPersonExtraValue 
> > ---------------------------------------------------------------------- 
> > Traceback (most recent call last): 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/nose/case.py",
>  
>
> > line 198, in runTest 
> >     self.test(*self.arg) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/server/tests/test_data_model.py",
>  
>
> > line 37, in test_GetPersonExtraValue 
> >     p1 = session.query(Person).get(1) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/query.py",
>  
>
> > line 829, in get 
> >     return self._get_impl(ident, loading.load_on_ident) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/query.py",
>  
>
> > line 862, in _get_impl 
> >     return fallback_fn(self, key) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 223, in load_on_ident 
> >     return q.one() 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/query.py",
>  
>
> > line 2736, in one 
> >     ret = self.one_or_none() 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/query.py",
>  
>
> > line 2706, in one_or_none 
> >     ret = list(self) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 90, in instances 
> >     util.raise_from_cause(err) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/util/compat.py",
>  
>
> > line 202, in raise_from_cause 
> >     reraise(type(exception), exception, tb=exc_tb, cause=cause) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/util/compat.py",
>  
>
> > line 186, in reraise 
> >     raise value 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 75, in instances 
> >     rows = [proc(row) for row in fetch] 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 75, in <listcomp> 
> >     rows = [proc(row) for row in fetch] 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 435, in _instance 
> >     loaded_instance, populate_existing, populators) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/orm/loading.py",
>  
>
> > line 496, in _populate_full 
> >     dict_[key] = getter(row) 
> >   File 
> > 
> "/Users/eric/Documents/Projects/ourlifestories/lib/python3.5/site-packages/sqlalchemy/dialects/mysql/json.py",
>  
>
> > line 65, in process 
> >     return json_deserializer(value) 
> >   File 
> > 
> "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py",
>  
>
> > line 312, in loads 
> >     s.__class__.__name__)) 
> > TypeError: the JSON object must be str, not 'bytes' 
> > 
> > Any help on what is wrong in my config or code would be helpful. 
> > 
> > 
> > 
> > 
> > 
> > -- 
> > 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+...@googlegroups.com <javascript:> 
> > <mailto:sqlalchemy+unsubscr...@googlegroups.com <javascript:>>. 
> > To post to this group, send email to sqlal...@googlegroups.com 
> <javascript:> 
> > <mailto:sqlal...@googlegroups.com <javascript:>>. 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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