OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

SQLAlchemy, get object not bound to a Session

  • Thread starter Thread starter Sardathrion - against SE abuse
  • Start date Start date
S

Sardathrion - against SE abuse

Guest
I am trying to get an collection of objects out of a database and pass it to another process that is not connected to the database. My code looks like the one below but I keep getting:

Code:
sqlalchemy.exc.UnboundExecutionError: Instance <MyClass at 0x8db7fec> is not bound to a Session; attribute refresh operation cannot proceed

When I try to look at the elements of my list outside of the get_list() method.

Code:
def get_list (obj):
    sesson = Session()
    lst = session.query(MyClass).all()
    session.close()
    return lst

However, if I use this:

Code:
def get_list_bis (obj)
    session = Session()
    return session.query(MyClass).all()

I am able to use the elements but worry about the state of the session since it was not closed.

What am I missing here?
<p>I am trying to get an collection of objects out of a database and pass it to another process that is not connected to the database. My code looks like the one below but I keep getting:</p>

<pre><code>sqlalchemy.exc.UnboundExecutionError: Instance <MyClass at 0x8db7fec> is not bound to a Session; attribute refresh operation cannot proceed
</code></pre>

<p>When I try to look at the elements of my list outside of the <code>get_list()</code> method.</p>

<pre><code>def get_list (obj):
sesson = Session()
lst = session.query(MyClass).all()
session.close()
return lst
</code></pre>

<p>However, if I use this:</p>

<pre><code>def get_list_bis (obj)
session = Session()
return session.query(MyClass).all()
</code></pre>

<p>I am able to use the elements but worry about the state of the session since it was not closed. </p>

<p>What am I missing here?</p>
 
Top