I am getting an exception:

sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on 
mapper mapped class User->users, SQL expression or this Session.

My engine creation code is in a static method of a class and is as follows:

            db_url = 'postgresql+psycopg2://myuser:'\
                     'mypw@localhost:5432/'\
                     'mydb'
            cls.engine = create_engine(db_url, echo=False)

at the module level I have this function:

def add_user(username, password,
             active=True, by=1,
             uid=None):
    """Create a User and add it to the database."""
    with Session(DatabaseORM.get_engine()) as session:
        if uid is not None:
            user = User(username=username,
                        password=password,
                        active=active,
                        created_by=by,
                        uid=uid)
        else:
            user = User(username=username,
                        password=password,
                        active=active,
                        created_by=by)

        session.add(user)

        session.commit()
        id_ = user.id_

    return id_

I tried adding:

session = Session.configure(bind=self.engine) 

in the with block but it told me configure is not an attribute of session.

Any help would be appreciated thank you.

- Jason

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/51b21161-dcd5-46f9-82bb-ec0480bfb170n%40googlegroups.com.

Reply via email to