I'm using sqlalchemy to my Flask application and run in python 3.7. Basically I just want only to get the value of self.tag_str and assume that the value of this variable is would be str but instead I got the value of type <class 'sqlalchemy.orm.attributes.InstrumentedAttribute'> which is not valid to convert in to json since json.loads accepts only string value. So I want to know if there is a way that i can get the original value ?
class TestModel(InternalJsonSerializer, CommonIntegraColumns):
__tablename__ = 'test_table_name'
__type__ = 'test_type'
id = Column('test1', BigInteger, primary_key=True, autoincrement=True)
col1 = Column('test2', String(2), nullable=False)
col2 = Column(
'test3', String(100), nullable=False)
col3 = Column('test4', String(100), nullable=False)
tag_str = Column('test5', Text, nullable=True)
@hybrid_property
def environ(self):
# @tag_str InstrumentedAttribute
if self.tag_str:
val = json.loads(str(self.tag_str))
return val
return None
@environ.setter
def set_environ(self, value):
if value is None:
self.tag_str = None
else:
self.tag_str = json.dumps(value)