Following Shorty tutorial for Werkzeug, I found out that I cannot use
autoload in sqlalchemy:-

sqlalchemy.exc.UnboundExecutionError
UnboundExecutionError: The MetaData is not bound to an Engine or
Connection. Execution can not proceed without a database to execute
against. Either execute with an explicit connection or assign the
MetaData's .bind to enable implicit execution.

So what I did is just import the local object from shorty.utils and
then bind the application.database_engine to metadata.

<code>
from shorty.utils import Session, metadata, url_for, get_random_uid,
local

application = local('application')
metadata.bind = application.database_engine

customer_table = Table('customers', metadata, schema='cvt',
autoload=True)

class Customer(object):
   def __init__(self, name):
       self.name = name

Session.mapper(Customer, customer_table)
</code>

Is it safe to use it this way ? While writing this also, another issue
came to my mind, this seem like autoload is run on every request
rather than on server start because the error only occurred when I
request the exact page that import the models. Server started just
fine and the actual Shorty app working like usual.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" 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/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to