types - SQL Alchemy - schema extraction with TypeDecorator -


i using typedecorator json extraction , model uses 1 of columns. storing python list objects using typedecorator.

def process_bind_param(self, value, dialect):     # etc...  def process_result_value(self, value, dialect):     # never gets called!!     if value not none:         return json.loads(value)     return value 

when store data in model uses decorator bind_param called appropriately. extract schema model using typedecorator via following:

table = table(table_name, meta, autoload=true, autoload_with=sengine) 

now query test (there many ways loop , extract):

for record in source.query(table).all():    print type(record.column_using_custom_type_list_object) == str    # returns true ... should false ... should of type list    # json.loads() returns type list ???    print record.column_using_custom_type_list_object[some_index]     # naturally prints character in string, not cell 

the problem process_result_value() not being called when table queried , object , column fetched. assumed sqlalchemy reflection handles dependencies? missing options in constructor transfer metadata requiring custom type decorator?

i'm not sure if it's same issue, think it's related enough me write answer here.

after storing object , trying read property, function process_result_value not called because object cached. (found here http://comments.gmane.org/gmane.comp.python.sqlalchemy.user/11406)

so solution invalidate object.

session.expire(obj) 

http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#refreshing-expiring


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -