[sqlalchemy] flush() issued, SQL seen, but database not updated?

2010-12-26 Thread jerryji
Hi,

I have been pulling my hair the whole day today: I have a web
application that runs fine, however, during unittest I noticed that
the test (PostgreSQL) database is not updated even after I issue the
flush() and see the SQL statement, which inserts fine by itself in
psql --


(Pdb) list
 73 user = model.User(user_name=user_name, email=email,
password=password)
 74
 75 dbsession = DBSession()
 76  - dbsession.add(user)
 77 try:
 78 dbsession.flush()
 79 except:
 80 raise
(Pdb) user
myapp.models.User object at 0xa9b8c4c
(Pdb) user.user_name, user.email, user.user_id
(u'test', u't...@example.com', u'f24a24217248480d90c1c370c103e07f')
(Pdb) n
 myapp/views/signup.py(77)signup_view()
- try:
(Pdb) n
 myapp/views/signup.py(78)signup_view()
- dbsession.flush()
(Pdb) n
...INFO sqlalchemy.engine.base.Engine.0x...24ac INSERT INTO users
(user_id, user_name, email) VALUES (%(user_id)s, %(user_name)s, %
(email)s)
...INFO sqlalchemy.engine.base.Engine.0x...24ac {'user_id':
u'f24a24217248480d90c1c370c103e07f', 'user_name': u'test', 'email':
u't...@example.com'}


I have dropped all the databases in my computer leaving only the test
db just to make absolute sure that I'm not connecting to one database
while looking into another.

What could have gone wrong?

Many thanks in advance!

Jerry

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] flush() issued, SQL seen, but database not updated?

2010-12-26 Thread Warwick Prince
Hi Jerry

Looks to me like you will need to swap your .flush for a .commit.commit 
will flush for you, then actually commit the changes to the DB.  :-)

Cheers
Warwick

 Hi,
 
 I have been pulling my hair the whole day today: I have a web
 application that runs fine, however, during unittest I noticed that
 the test (PostgreSQL) database is not updated even after I issue the
 flush() and see the SQL statement, which inserts fine by itself in
 psql --
 
 
 (Pdb) list
 73user = model.User(user_name=user_name, email=email,
 password=password)
 74
 75dbsession = DBSession()
 76  -dbsession.add(user)
 77try:
 78dbsession.flush()
 79except:
 80raise
 (Pdb) user
 myapp.models.User object at 0xa9b8c4c
 (Pdb) user.user_name, user.email, user.user_id
 (u'test', u't...@example.com', u'f24a24217248480d90c1c370c103e07f')
 (Pdb) n
 myapp/views/signup.py(77)signup_view()
 - try:
 (Pdb) n
 myapp/views/signup.py(78)signup_view()
 - dbsession.flush()
 (Pdb) n
 ...INFO sqlalchemy.engine.base.Engine.0x...24ac INSERT INTO users
 (user_id, user_name, email) VALUES (%(user_id)s, %(user_name)s, %
 (email)s)
 ...INFO sqlalchemy.engine.base.Engine.0x...24ac {'user_id':
 u'f24a24217248480d90c1c370c103e07f', 'user_name': u'test', 'email':
 u't...@example.com'}
 
 
 I have dropped all the databases in my computer leaving only the test
 db just to make absolute sure that I'm not connecting to one database
 while looking into another.
 
 What could have gone wrong?
 
 Many thanks in advance!
 
 Jerry
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.