1. check on the isolation level you're using, and as a guarantee that you read new rows, make sure the second "reader" session is beginning its transaction *after* the first transaction is completed.

2. if the second session wishes to re-read the rows within its own transaction, and you are using a lower isolation level like read-committed, you can first call session.expire_all(), or the populate_existing() method on the Query which will force a refresh of objects as rows are read.

https://en.wikipedia.org/wiki/Isolation_%28database_systems%29

http://docs.sqlalchemy.org/en/rel_1_0/orm/session_transaction.html?highlight=isolation#setting-transaction-isolation-levels

http://docs.sqlalchemy.org/en/rel_1_0/orm/session_transaction.html#managing-transactions

http://docs.sqlalchemy.org/en/rel_1_0/orm/session_state_management.html#session-expire

http://docs.sqlalchemy.org/en/rel_1_0/orm/session_api.html?highlight=expire_all#sqlalchemy.orm.session.Session.expire_all

http://docs.sqlalchemy.org/en/rel_1_0/orm/query.html?highlight=populate_existing#sqlalchemy.orm.query.Query.populate_existing



On 6/22/15 8:38 PM, Balaji Pattewar wrote:


      Hi all,

I am using simple SQLALCHEMY implementation.

I have two classes Svc, Mani

class Svc(Base):
     ''' class to map 'service' table in database
        '''
        __tablename__ = 'svc'
        __table_args__ = {'autoload': True}
      manis = relationship('Mani')
What I found that upon issuing session.query(Svc).all()
  only refreshes Svc (svctable) entries from the database, but the manis 
collection
is queried only once (on first query ) and it is not refreshed every time 
session.query(Svc)
is issued.

What should I set so that manis collection should issue query and refresh and
sync itself with database everytime it is accessed or atleast everytime
session.query(Svc).all is issued.
You can see in detail steps for the issue.
I have two different session connected to the database using two different
terminals.
-------------------------------
In terminal I


svcs = session.query(Svc).all()
svc1 = svcs[0]

(halt)
------------------------------
In terminal II

svcs = session.query(Svc).all()
svc1 = svcs[0]
for mani in svc1.manis:
     printmani.name <http://mani.name>

(halt)
----------------------------------
In terminal I
(continue from previous state)
test_mani = Mani()
svc1.manis.append(test_mani)
session.commit()
# New test_mani is commited to DB
# Do the query

svcs = session.query(Svc).all()
svc1 = svcs[0]
for mani in svc1.manis:
     printmani.name <http://mani.name>
# The new mani is printed
(halt)
--------------------------------

In terminal II
(continue from previous state)

requery
svcs = session.query(Svc).all()
svc1 = svcs[0]
for mani in svc1.manis:
     printmani.name <http://mani.name>

# The newly added test_mani is not part of
# svc1.mani even after Svc is requried.



Thanks in advance for your guidance.

regards
Balaji

--
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 [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to