Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch a value of SQLalchemy instrumentedattribute

How can I fetch the value of a InstrumentedAttribute object in SQLalchemy:

(Pdb) ResultLine.item_reference_1
<sqlalchemy.orm.attributes.InstrumentedAttribute object at 0x793dc90>

The above statement prints me the sqlalchemy object.

What I actually need is the value associated with it.

like image 734
maruthi reddy Avatar asked Jan 14 '23 22:01

maruthi reddy


1 Answers

There is no value associated with an InstrumentedAttribute; you are looking at a table declaration, not a result set. InstrumentedAttribute is used to define a relationship to another table, for example.

Query the database for results, and the resulting objects will have the reference filled in for you:

 for res in session.query(ResultLine).filter(somefilter):
     print res.item_reference_1
like image 145
Martijn Pieters Avatar answered Jan 22 '23 04:01

Martijn Pieters