Re: [Sqlalchemy-users] session context proposal

2006-05-16 Thread Michael Bayer
On May 11, 2006, at 10:31 PM, Daniel Miller wrote: I think by default it should require a session.save(u) before the flush (that's exactly what Hibernate does). its the default. Now if someone happens to want that type of magic, then they can use one of the _explicit_ recipes to get that

Re: [Sqlalchemy-users] session context proposal

2006-05-16 Thread Michael Bayer
On May 12, 2006, at 12:10 PM, Robin Munn wrote: "If you prefer to have one default session that all your objects are associated with by default, then import the thread-local mod at the start of your code. (Insert detailed instructions here). This will give you one global session object, used au

Re: [Sqlalchemy-users] session context proposal

2006-05-16 Thread Daniel Miller
Hey Mike, Here's a new patch, which uses your mapper extension idea rather than the session_context mapper() parameter. I also removed orm.session.current_session and friends, and updated the unitofwork documentation accordingly. Note that I have implemented the new mapper extension method you

Re: [Sqlalchemy-users] session context proposal

2006-05-16 Thread Robin Munn
On 5/11/06, Michael Bayer <[EMAIL PROTECTED]> wrote: the "threadlocal" mod has been removed from the tutorial as well as all mention of it. For the sake of the people like me who learned SQLAlchemy in the 0.1.x series, or the people who prefer the thread-local style of session management, I thi

Re: [Sqlalchemy-users] session context proposal

2006-05-15 Thread Michael Bayer
On May 14, 2006, at 1:42 AM, Daniel Miller wrote: I'm not sure how many (if any) tests this may have broken. I've always had problems trying to run the tests...is there anything special I need to do? Give it a whirl and let me know what you think. not every unit test has been converted to

Re: [Sqlalchemy-users] session context proposal

2006-05-12 Thread Michael Bayer
This seemed to get lost in sourceforge's email queue, resending On May 11, 2006, at 10:31 PM, Daniel Miller wrote: I think by default it should require a session.save(u) before the flush (that's exactly what Hibernate does). its the default. Now if someone happens to want that type of m

Re: [Sqlalchemy-users] session context proposal

2006-05-12 Thread Daniel Miller
Michael Bayer wrote: The mapper will have an optional session_context parameter. It will provide the exact same functionality as current_session(), but provides additional flexibility because each mapper can have it's own context. OK, so you want to put it in mapper, yes thats the other wa

Re: [Sqlalchemy-users] session context proposal

2006-05-11 Thread Daniel Miller
Michael Bayer wrote: we agree, that there should be some way to turn on this feature: u = User()# 'u' is now automatically in the session session.flush()# 'u' is now saved. I think by default it should require a session.save(u) before the flush (that's exactly what Hibernate

Re: [Sqlalchemy-users] session context proposal

2006-05-11 Thread Michael Bayer
On May 11, 2006, at 12:03 AM, Daniel Miller wrote: The thread-local mod is implied in all the documentation examples for 0.2; therefore it will be used by most if not all SA users at least at first. When a project starts to move from simple experimentation mode into a full-blown complex p

Re: [Sqlalchemy-users] session context proposal

2006-05-11 Thread Michael Bayer
On May 11, 2006, at 12:03 AM, Daniel Miller wrote: As I've already said, I object to adding a __call__() method in addition to the "current" property because it adds confusion about the "one obvious way" to get the current session. The "reference implementation" of your "session context" s

Re: [Sqlalchemy-users] session context proposal

2006-05-10 Thread Michael Bayer
dan - no need to get defensive, the list has had enough flame wars for one day. this session context stuff is so not a big deal. we can go around and around, its not going to go anywhere until you answer me this question: we agree, that there should be some way to turn on this feature

Re: [Sqlalchemy-users] session context proposal

2006-05-10 Thread Daniel Miller
Michael Bayer wrote: On May 2, 2006, at 10:13 PM, Daniel Miller wrote: If you're interested, I have lot's of comments like this on various parts of the SQLAlchemy API. im sure you do, but one thorny issue of SA is that it supports multiple programming styles, particularly in 0.2, where y

RE: [Sqlalchemy-users] session context proposal

2006-05-05 Thread Daniel Miller
That's a good point. Yes I agree, that solution is good (with the extra None param in getattr of course). I would also do an explicit check for None like this: def default_session(obj=None): default_session = getattr(obj, "__default_session__", None) if default_session is not None:

Re: [Sqlalchemy-users] session context proposal

2006-05-04 Thread Gustavo Niemeyer
> def default_session(obj=None): > default_session = getattr(obj, "__default_session__") That of course should include None as the third argument, otherwise the AttributeError is raised as well. -- Gustavo Niemeyer http://niemeyer.net ---

Re: [Sqlalchemy-users] session context proposal

2006-05-04 Thread Michael Bayer
On May 2, 2006, at 8:42 PM, Daniel Miller wrote: Oh, and use a try/except block rather than hasattr. It's more pythonic... So with all those suggestions this is what we end up with: def default_session(obj=None): try: return obj.__default_session__() except AttributeError:

Re: [Sqlalchemy-users] session context proposal

2006-05-03 Thread Michael Bayer
On May 2, 2006, at 10:13 PM, Daniel Miller wrote: If you're interested, I have lot's of comments like this on various parts of the SQLAlchemy API. im sure you do, but one thorny issue of SA is that it supports multiple programming styles, particularly in 0.2, where you can use an expli

Re: [Sqlalchemy-users] session context proposal

2006-05-03 Thread Gustavo Niemeyer
> Right? Yes, that's fine. That (the first version) will work with > either classmethod or instance method. I don't see much use in an > instance method ATM, but you're right why not allow it? It will allow > (tempt?) people to do things they shouldn't do, but hey this is Python > and we're consent

Re: [Sqlalchemy-users] session context proposal

2006-05-02 Thread Daniel Miller
Michael Bayer wrote: also i dont understand how sticking a __call__() on SessionContext would have any impact on its existing get/set/del operations. It's totally unnecessary and it clutters the interface. Unnecessary methods/properties/etc. are confusing because they make people wonder "

Re: [Sqlalchemy-users] session context proposal

2006-05-02 Thread Daniel Miller
Michael Bayer wrote: ive liked __session__ all along. Dan's concern is that people will think __session__ returns the session which the instance is attached to, not just the "contextual" session which may be different. Yeah, I'm not thrilled about __session__ for that exact reason. However,

Re: [Sqlalchemy-users] session context proposal

2006-05-02 Thread Michael Bayer
ive liked __session__ all along. Dan's concern is that people will think __session__ returns the session which the instance is attached to, not just the "contextual" session which may be different. In my original proposal, i was going to just have __session__ just return wahtever contextu

Re: [Sqlalchemy-users] session context proposal

2006-05-02 Thread Gustavo Niemeyer
> how about 'contextualsession' or somethingI really dislike the > name "contextsession". __session__ would probably be fine, unless you're afraid to conflict with something else. We use __int__ to get ints out of an object, __nonzero__ to get a boolean, and so on. Using __session__ looks li

Re: [Sqlalchemy-users] session context proposal

2006-05-02 Thread Gustavo Niemeyer
> So would it work like this: > > callable = MyClass.__sessioncontext__ > session = callable() > > or like this: > > callable = MyClass.__sessioncontext__() > session = callable() > > I'm not really liking the second one because it requires this to get a > session directly from the object: >

Re: [Sqlalchemy-users] session context proposal

2006-05-01 Thread Michael Bayer
how about 'contextualsession' or somethingI really dislike the name "contextsession". also i dont understand how sticking a __call__() on SessionContext would have any impact on its existing get/set/del operations. On May 1, 2006, at 9:45 PM, Daniel Miller wrote: Michael Bayer wrote:

Re: [Sqlalchemy-users] session context proposal

2006-05-01 Thread Daniel Miller
Michael Bayer wrote: I havent done anything with SessionContext as of yet, but i had in mind that __sessioncontext__ would return a callable. when you call that returned callable, you get the session. So would it work like this: callable = MyClass.__sessioncontext__ session = callable()

Re: [Sqlalchemy-users] session context proposal

2006-05-01 Thread Michael Bayer
dan - great news, I can continue building on what we've been doing. I havent done anything with SessionContext as of yet, but i had in mind that __sessioncontext__ would return a callable. when you call that returned callable, you get the session. on SessionContext this would mean just

Re: [Sqlalchemy-users] session context proposal

2006-04-30 Thread Daniel Miller
Michael Bayer wrote: On Apr 27, 2006, at 11:05 PM, Daniel Miller wrote: the __session__() method is only called to get a session, *when the instance is not already associated with a session*. this method is merely there as the standard way to plug into systems such as the SessionContext

Re: [Sqlalchemy-users] session context proposal

2006-04-28 Thread Gustavo Niemeyer
> my current proposal regarding the association of objects to sessions, > as well as the optional association of objects and classes to > "session contexts", is as follows: (...) That's very nice! I'm looking forward to refactor our application to use this interface. > # returns the ses

Re: [Sqlalchemy-users] session context proposal

2006-04-28 Thread Michael Bayer
On Apr 27, 2006, at 11:05 PM, Daniel Miller wrote: I assume you're implicitly referring to any method that would call Session._bind_to(). Personally, I think Session._bind_to() should raise an exception if the object-to-be-bound is associated with some other _open_ session (rather than sile

Re: [Sqlalchemy-users] session context proposal

2006-04-27 Thread Daniel Miller
Michael Bayer wrote: my current proposal regarding the association of objects to sessions, as well as the optional association of objects and classes to "session contexts", is as follows: ... Great! this looks pretty good. I do have a few comments on your other email though. Here goes...

[Sqlalchemy-users] session context proposal

2006-04-27 Thread Michael Bayer
my current proposal regarding the association of objects to sessions, as well as the optional association of objects and classes to "session contexts", is as follows: Session - represents a current unit of work session and an associated collection of objects. a particular object is only i