[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.



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

2010-12-26 Thread jerryji
BTW, during testing, this _persistent_ user object dropped my jaw --


 myapp/views/signup.py(73)signup_view()
- user = model.User(user_name=user_name, email=email,
password=password)
(Pdb) n
(Pdb) user
pweb.models.User object at 0xbbb20ec
(Pdb) user = None
(Pdb) user
pweb.models.User object at 0xbbb20ec
(Pdb) user2 = model.User(user_name=user_name, email=email,
password=password)
(Pdb) user2
pweb.models.User object at 0xbbb2f0c
(Pdb) user2 = None
(Pdb) user2
(Pdb)


Though I'm not sure if that's related to my problem at hand.

Jerry

On Dec 26, 9:55 pm, jerryji jerryji1...@gmail.com wrote:
 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.



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

2010-12-26 Thread jerryji
Just to (partially) answer myself -- by enabling db logging, I see
that the insertion is not seen in other db sessions because it gets
rolled back, most likely done in unittest's setUp() and tearDown() --
though I still don't understand the persistent user object thing

Jerry

On Dec 26, 10:02 pm, jerryji jerryji1...@gmail.com wrote:
 BTW, during testing, this _persistent_ user object dropped my jaw --

  myapp/views/signup.py(73)signup_view()

 - user = model.User(user_name=user_name, email=email,
 password=password)
 (Pdb) n
 (Pdb) user
 pweb.models.User object at 0xbbb20ec
 (Pdb) user = None
 (Pdb) user
 pweb.models.User object at 0xbbb20ec
 (Pdb) user2 = model.User(user_name=user_name, email=email,
 password=password)
 (Pdb) user2
 pweb.models.User object at 0xbbb2f0c
 (Pdb) user2 = None
 (Pdb) user2
 (Pdb)
 

 Though I'm not sure if that's related to my problem at hand.

 Jerry

 On Dec 26, 9:55 pm, jerryji jerryji1...@gmail.com wrote:

  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] Re: flush() issued, SQL seen, but database not updated?

2010-12-26 Thread Michael Bayer

On Dec 26, 2010, at 9:02 AM, jerryji wrote:

 BTW, during testing, this _persistent_ user object dropped my jaw --

I think the user = None assignment has no effect in pdb since the existing 
contents of locals() is fixed.

Otherwise the rollback behavior of your tests is why the PG database has no 
end result for the SQL emitted in the tests.


 
 
 myapp/views/signup.py(73)signup_view()
 - user = model.User(user_name=user_name, email=email,
 password=password)
 (Pdb) n
 (Pdb) user
 pweb.models.User object at 0xbbb20ec
 (Pdb) user = None
 (Pdb) user
 pweb.models.User object at 0xbbb20ec
 (Pdb) user2 = model.User(user_name=user_name, email=email,
 password=password)
 (Pdb) user2
 pweb.models.User object at 0xbbb2f0c
 (Pdb) user2 = None
 (Pdb) user2
 (Pdb)
 
 
 Though I'm not sure if that's related to my problem at hand.
 
 Jerry
 
 On Dec 26, 9:55 pm, jerryji jerryji1...@gmail.com wrote:
 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.
 

-- 
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.



[sqlalchemy] SQLAlchemy NoSuchTableError

2010-12-26 Thread webjunkie
Im dveloping an app with Pylons and using sqlalchemy reflection on a
postgres
db. It all seems to work so far, but when I run tests using nose I get
the
following error

Traceback (most recent call last):
  File /home/webjunkie/www/env/bin/nosetests, line 8, in module
load_entry_point('nose==0.11.3', 'console_scripts', 'nosetests')()
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
nose-0.11.3-
py2.6.egg/nose/core.py, line 117, in __init__
**extra_args)
  File /usr/lib/python2.6/unittest.py, line 816, in __init__
self.parseArgs(argv)
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
nose-0.11.3-
py2.6.egg/nose/core.py, line 134, in parseArgs
self.config.configure(argv, doc=self.usage())
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
nose-0.11.3-
py2.6.egg/nose/config.py, line 324, in configure
self.plugins.begin()
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
nose-0.11.3-
py2.6.egg/nose/plugins/manager.py, line 93, in __call__
return self.call(*arg, **kw)
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
nose-0.11.3-
py2.6.egg/nose/plugins/manager.py, line 161, in simple
result = meth(*arg, **kw)
  File /home/webjunkie/www/env/lib/python2.6/site-packages/
Pylons-1.0-
py2.6.egg/pylons/test.py, line 74, in begin
relative_to=path)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py, line
204, in
loadapp
return loadobj(APP, uri, name=name, **kw)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py, line
225, in
loadobj
return context.create()
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py, line
625, in
create
return self.object_type.invoke(self)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py, line
110, in
invoke
return fix_call(context.object, context.global_conf,
**context.local_conf)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/util/
fixtypeerror.py, line
57, in fix_call
val = callable(*args, **kw)
  File /var/www/Mascotitas/mascotitas/config/middleware.py, line 37,
in
make_app
config = load_environment(global_conf, app_conf)
  File /var/www/Mascotitas/mascotitas/config/environment.py, line
49, in
load_environment
init_model(engine)
  File /var/www/Mascotitas/mascotitas/model/__init__.py, line 89,
in
init_model
user_table = schema.Table('users', Base.metadata, autoload=True,
autoload_with=engine)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/schema.py, line 209,
in
__new__
table._init(name, metadata, *args, **kw)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/schema.py, line 257,
in
_init
include_columns=include_columns)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/base.py, line
1863,
in reflecttable
self.dialect.reflecttable(conn, table, include_columns)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/default.py,
line
228, in reflecttable
return insp.reflecttable(table, include_columns)
  File /home/webjunkie/www/env/lib/python2.6/site-
packages/SQLAlchemy-0.6.5-py2.6.egg/sqlalchemy/engine/reflection.py,
line
411, in reflecttable
raise exc.NoSuchTableError(table.name)
sqlalchemy.exc.NoSuchTableError: users

Nose is configured to use an sqlite db.

My model init is as follows

Session.configure(bind=engine, autoflush=True,
autocommit=False)
Base.metadata.reflect(bind=engine)
 user_table = schema.Table('users', Base.metadata, autoload=True,
autoload_with=engine)
orm.mapper(User, user_table)

Im using sqlalchemy 6.5 what could be the problem?. Any help is
appreciated.

-- 
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.