On Fri, Jun 12, 2009 at 5:12 PM, 오현성<[email protected]> wrote:
> Hi there!
>
> I'm new to Pylons and Python, though I've used PHP, Rails, PostgreSQL etc a
> little bit in the past.
>
> I'm currently working through the Definitive Guide to Pylons, and I've run
> into problems in Chapter 8 (Starting the SimpleSite tutorial,
> http://pylonsbook.com/en/1.0/starting-the-simplesite-tutorial.html ). When I
> run paster setup-app development.ini, I get the following error:
>
> $ paster setup-app development.ini
> 08:51:16,056 INFO [simplesite.websetup] Adding homepage...
> Traceback (most recent call last):
> File "/home/username/pylonsenv/bin/paster", line 8, in <module>
> File "/home/username/SimpleSite/simplesite/websetup.py", line 26, in
> <module>
> meta.Session.commit()
> File
> "/home/username/pylonsenv/lib/python2.5/site-packages/SQLAlchemy-0.5.4p2-py2.5.egg/sqlalchemy/orm/session.py",
> line 260, in connection
> engine = self.session.get_bind(bindkey, **kwargs)
> File
> "/home/username/pylonsenv/lib/python2.5/site-packages/SQLAlchemy-0.5.4p2-py2.5.egg/sqlalchemy/orm/session.py",
> line 890, in get_bind
> ', '.join(context)))
> sqlalchemy.exc.UnboundExecutionError: Could not locate a bind configured on
> mapper Mapper|Tag|tag or this Session
>
> I've tried making various small changes to model.__init__.py and
> websetup.py, but got the same error each time. I'm not entirely sure how to
> interpret it. This kind of error seems to be fairly common, but I haven't
> found identical errors or solutions on Google or anywhere yet. Any help
> would be much appreciated.
It's looking for an engine to execute the commit on. It looks first
in the session, then in the metadata. So your model.init_model()
should set up the session using bind=engine. As it shows on page 172:
sm = orm.sessionmaker(autoflush=True, autocommit=False, bind=engine)
I think in SA 0.5 you can omit all the arguments except bind, but
that's not pertinent to your immediate problem.
The second question is whether init_model(engine) is being called in
myapp.config.environment.load_environment(), as it should be.
The third question is whether myapp.websetup.setup_app is calling
load_environment() like my sample application here is. If so, then
you should be able to put
log.debug("Engine is %s", meta.Session.bind)
after that line and have it print out an engine.
All three of these have to be in place in order to avoid this error.
setup-app is not that widely used, so it's possible there's an
inconsistency in the documentation somewhere.
By the way, there is another way to configure the session which came
into vogue after the book was written. You don't have to worry about
it now but just so you're aware of it in case you encounter it, it's
to move the sm and Session assignments to the meta module (without a
bind argument), and then to modify the Session in place in
init_model():
meta.Session.configure(bind=engine)
This helps in some edge situations where you want to refer to a
session in a global expression (after the model has been imported but
before init_model has been called), but is not strictly necessary.
--
Mike Orr <[email protected]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---