[sqlalchemy] using an unmapped object to get the mapped object from a session

2013-01-10 Thread Chris Withers
Hi All, If I have an unmapped object which has had some attributes set on it, what would be the best way to use that object to load a mapped object? I didn't noticed a session.lookup(myobj) method ;-) The specific semantics I'm looking for would be to find the rows, if there's no rows,

Re: [sqlalchemy] Unicode warnings - show offending value

2013-01-10 Thread Felix Schwarz
Am 10.01.2013 00:45, schrieb Michael Bayer: Can't, because as a python warning, the warnings lib caches that message permanently, to support the typical case that the warnings filter is set to once. If the message were unique for every value your app would slowly leak memory I see, bad

[sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
It seems engine created using *create_engine* is not freed after cleanup of a session. Object graph indicates that event.listen for pool is holding reference to engine even after session is garbage collected. *What is the right way/api to delete an engine ?* *UseCase* As there are lot of

[sqlalchemy] Plans for function-based indexes?

2013-01-10 Thread Przemyslaw Wegrzyn
Hi! Is there any plan for supporting declarative, function-based indexes? I'm pretty sure I've seen a statement somewhere about supporting it in 0.8.x, but can't find it at the moment. Right now I have to use constructs like this one: event.listen(Line.__table__, 'after_create', DDL(CREATE

[sqlalchemy] setting use_labels=True for ORM generated selects?

2013-01-10 Thread Bill Curtis
Hi... We are seeing many queries generated via relationship() issue this a warning with this advice: Consider use_labels for select() statements. I'm trying to figure out how to set use_labels, or apply_labels on the generated query, but I'm completely stumped. Is it possible to do this, or

Re: [sqlalchemy] setting use_labels=True for ORM generated selects?

2013-01-10 Thread Michael Bayer
On Jan 10, 2013, at 11:48 AM, Bill Curtis wrote: Hi... We are seeing many queries generated via relationship() issue this a warning with this advice: Consider use_labels for select() statements. I'm trying to figure out how to set use_labels, or apply_labels on the generated query,

Re: [sqlalchemy] setting use_labels=True for ORM generated selects?

2013-01-10 Thread Bill Curtis
Hi Michael, If you have time to take a look, I put up a short gist with some additional detail: https://gist.github.com/4505226 We are doing this: # 'self' is an Article model, which is 1-to-many with Comments, which are 1-to-1 with Users, which is 1-to-1 with Profile. # All four

Re: [sqlalchemy] setting use_labels=True for ORM generated selects?

2013-01-10 Thread Michael Bayer
I need to run it, so can you express all four tables profiles, comments, articles, users with enough columns as are referenced here, and some plain placeholder classes User, Article, Comment, Profile?I don't see the usual things that produce that warning so you might be hitting some

Re: [sqlalchemy] setting use_labels=True for ORM generated selects?

2013-01-10 Thread Bill Curtis
Okay, cool. I'll put together a runnable .py file. On Thu, Jan 10, 2013 at 12:19 PM, Michael Bayer mike...@zzzcomputing.comwrote: I need to run it, so can you express all four tables profiles, comments, articles, users with enough columns as are referenced here, and some plain placeholder

Re: [sqlalchemy] Unicode warnings - show offending value

2013-01-10 Thread Bill Curtis
Felix, Another technique I have used, in case you are not aware of it: I add this: import traceback util.warn(str(traceback.format_stack())) to whichever sqlalchemy .py file is producing the error, right at the point where the error is emitted. Then whenever it happens, you get a full

Re: [sqlalchemy] Plans for function-based indexes?

2013-01-10 Thread Michael Bayer
On Jan 10, 2013, at 9:08 AM, Przemyslaw Wegrzyn wrote: Hi! Is there any plan for supporting declarative, function-based indexes? I'm pretty sure I've seen a statement somewhere about supporting it in 0.8.x, but can't find it at the moment. Right now I have to use constructs like this

Re: [sqlalchemy] using an unmapped object to get the mapped object from a session

2013-01-10 Thread Michael Bayer
On Jan 10, 2013, at 3:35 AM, Chris Withers wrote: Hi All, If I have an unmapped object which has had some attributes set on it, what would be the best way to use that object to load a mapped object? I didn't noticed a session.lookup(myobj) method ;-) what is it looking up ?what's

Re: [sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
On Jan 10, 2013, at 8:25 AM, Anoop K wrote: It seems engine created using create_engine is not freed after cleanup of a session. Object graph indicates that event.listen for pool is holding reference to engine even after session is garbage collected. What is the right way/api to delete an

Re: [sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
I tried session.bind.dispose() and NullPool. But engine *is still not cleared*. It still seems to have some reference from SessionEventsDispatch = sqlalchemy.event._DispatchDescriptor. On Friday, 11 January 2013 05:24:19 UTC+5:30, Michael Bayer wrote: On Jan 10, 2013, at 8:25 AM, Anoop K

Re: [sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
this is all about whatever you've done specifically. If you have the Session instance still around, where my_session.bind still points to your Engine, then that Engine is still in memory - you're holding a reference to it. Similarly, if you've assigned an event to the Session class whose

Re: [sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
I am not holding engine or using event.listen anywhere. Code is as simple as def create_sn(url): engine = create_engine(url) return sessionmaker(bind=engine)(expire_on_commit=False) sn = create_sn(url) try: sn... finally: sn.close() sn.bind.dispose() In engine/strategies.py

Re: [sqlalchemy] SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
On Jan 11, 2013, at 12:42 AM, Anoop K wrote: I am not holding engine or using event.listen anywhere. Code is as simple as def create_sn(url): engine = create_engine(url) return sessionmaker(bind=engine)(expire_on_commit=False) sn = create_sn(url) try: sn... finally:

[sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
I tried the code in my setup.(SQLAlchemy-0.7.8-py2.6). Looks like engine did not got GCed. *[anoop@localhost tmp]$ p engtest.py * *about to delete sn...* *about to gc.collect()...* *Traceback (most recent call last):* * File engtest.py, line 31, in module* *assert engine_is_removed*

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
there's some side effect occurring as a result of how 0.7 creates a new subclass when using sessionmaker. Since you don't need a sessionmaker here, please use this form: return Session(bind=engine, expire_on_commit=False) or upgrade to 0.8.0b2. On Jan 11, 2013, at 1:08 AM, Anoop K wrote:

[sqlalchemy] Events (load and after_attach) for instance stamping

2013-01-10 Thread YKdvd
In the MySQL system I'm redoing with SQLAlchemy, there is effectively a master' schema that exists once top-level stuff (including a table describing projects) , and project schemas (one identical set of tables per project), which have project-level stuff. When an object is retrieved from a

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
*Great ...* Session(bind=engine, expire_on_commit=False) fixed the problem. Looks like 0.8.0b2 is BETA. Is it OK to use in production ? Thanks Anoop On Friday, 11 January 2013 11:48:29 UTC+5:30, Michael Bayer wrote: there's some side effect occurring as a result of how 0.7 creates a new

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
the sessionmaker() object is not GC-able in 0.7 right now due to event mechanics. This issue does not exist in 0.8. I'll add a note. On Jan 11, 2013, at 1:18 AM, Michael Bayer wrote: there's some side effect occurring as a result of how 0.7 creates a new subclass when using

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
its beta very close to release On Jan 11, 2013, at 1:29 AM, Anoop K wrote: Great ... Session(bind=engine, expire_on_commit=False) fixed the problem. Looks like 0.8.0b2 is BETA. Is it OK to use in production ? Thanks Anoop On Friday, 11 January 2013 11:48:29 UTC+5:30, Michael Bayer

Re: [sqlalchemy] Events (load and after_attach) for instance stamping

2013-01-10 Thread Michael Bayer
On Jan 11, 2013, at 1:22 AM, YKdvd wrote: SQLA's event system has the after_attach session event. Hooking into this works for new instances I attach to a session with add(), but does't fire when items are loaded from a query - presumably attached means direct userland attachment only,

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Michael Bayer
the event mechanics issue applies to 0.7 and 0.8. while the engine will be gc'ed in 0.8, the sessionmaker itself, if used, will still create an anonymous subclass that is not cleared. creating many ad-hoc sessionmaker() objects, while this was not its intended use, will cause memory to

Re: [sqlalchemy] Re: SQLAlchemy Engine cleanup

2013-01-10 Thread Anoop K
OK. So does Session(bind=engine, expire_on_commit=False) usage always guarantee that engine and all other associated objects are cleared on doing a session.close() + engine.dispose(). On Friday, 11 January 2013 12:27:16 UTC+5:30, Michael Bayer wrote: the event mechanics issue applies to

Re: [sqlalchemy] Events (load and after_attach) for instance stamping

2013-01-10 Thread YKdvd
On Friday, January 11, 2013 2:34:09 AM UTC-4, Michael Bayer wrote: you can associate the instance event with the mapper() callable or Mapper class, and it will take effect for all mapped classes. I think that would work for my case, although I'm a little fuzzy as to the exact syntax to