Forgive my attention grabbing headline but I think Pylons integration
with create_engine() needs a serious overhaul, small as it may be.
id like to apply the "pool_recycle" argument to create_engine().
however pylons.database provides no way to propigate arbitrary keys
from the .ini file to create_engine(); its hardcoded to just "dburi"
and "echo". Additionally, if I stick a pylons.database.create_engine
() statement inside of config/environment.py, pylons.database will
cache that particular engine based on its URI as well as the string
version of its **kwargs, therefore pylons.database.session_context
still has no way to get at those options, since it doesnt have those
**kwargs with which to construct the key. but not only that, its not
even caching it in the same dictionary that the running application
will use.
i tried using this code in environment.py:
kwargs = {}
uri, echo = database.get_engine_conf()
kwargs['echo'] = echo
database.get_engines()['%s|%s' % (uri, str(kwargs))] =
database.create_engine(uri, echo=echo, pool_recycle=7200)
which would at best be a horrible kludge to get this working, as i am
imitating a private key-making function to make it work. but even
*that* doesnt work, because get_engines() at that point returns the
_db_engines dict thats inside of database.py, but when the app
actually runs, it returns the _db_engines thats on top of "g".
setting it within lib/app_globals.py doesnt do any better. So I have
to stick it inside of lib/base.py which is not at all where
environmental options should be configured.
design changes i would make:
- definite: have just *one* dictionary which stores database engines,
not two. database._db_engines and g._db_engines, if you even need
g._db_engines at all (why is it needed in two places?) should be *the
same dictionary*. having two of the same thing is useless and
creates ambiguity.
- no reason why not: alter pylons.database.create_engine() to
provide a "config_key" argument, which specifies exactly what key a
particular database engine will be stored under. put this key as
in .ini as well under sqlalchemy.key or similar so it can be affected
from both places.
- nice to have: allow support for *any* keyword under
sqlalchemy.XXXXX to be propigated from the .ini file to create_engine
(), not just 'uri' and 'echo'. have awareness of the well known
kwargs so that types can be changed from strings to ints/booleans as
needed.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---