How do I save to DB using paster shell

91 views
Skip to first unread message

Alex King

unread,
Jul 26, 2009, 12:40:48 AM7/26/09
to turbo...@googlegroups.com
Just starting out with a TG2 project, and I would like to manipulate
data in my DB, from paster shell.

I am trying to set up my own username (in a project quickstarted with
authentication and authorization.) I added a user through /admin but no
password is assigned when this is done.

What I have so far, after a bit of digging around and guesswork:

paster shell development.ini
In [1]:
u=model.DBSession.query(model.User).filter_by(user_name="alex").one()

In [2]: u.password="alex"

In [4]: model.DBSession.flush()

In [5]: model.DBSession.commit()
...
AssertionError: Transaction must be committed using the transaction manager


What is going wrong?

I suggest a couple of documentation updates:

1. The auth/authen documentation spends a lot of time on how auth is
plugable (which is good - I'd like to be able to use openID or LDAP in
future projects), but could give more detail on the how to quickly add
users to the default setup.

2. paster shell is mentioned as a convenient way to interact with the DB
in a couple of places, but it doesn't actually say how to commit changes
to the DB that I can see.

Cheers,
Alex

David Broudy

unread,
Jul 26, 2009, 12:50:33 AM7/26/09
to turbo...@googlegroups.com
On Jul 25, 2009, at 10:40 PM, Alex King wrote:


Just starting out with a TG2 project, and I would like to manipulate
data in my DB, from paster shell.

I am trying to set up my own username (in a project quickstarted with
authentication and authorization.)  I added a user through /admin but no
password is assigned when this is done.


Take a look at websetup.py, that will create your initial data when you run setup-app, so you shouldn't have to use the shell.

But if you do want to use the shell, you can do:

import transaction
transaction.commit()

Hope that helps.


Dave Broudy
Three Aspen Software
2922 Evergreen Pkwy, Suite 311
Evergreen, CO 80439
Office: 303.278.0908 // Fax: 303.500.3112
AIM/YIM: dbroudy
Reply all
Reply to author
Forward
0 new messages