Michael Bayer wrote:
> I've implemented all the missing "class-level" methods on
> ScopedSession in r3212, so you should be able to call refresh().
Great, thanks. I'll check this out.
> But also, if you want to say Session(), then work with it, that is
> also the intended usage model, although the Session.xxx methods
> should in theory be all you need.
Why should I instantiate session = Session() if everything off the class
is directly available ?
> Also i cannot reproduce your "order_by" keyword argument issue; the
> mapper() function provided by ScopedSession passes all **kwargs
> generically through to the actual mapper() function, so you'll have
> to show me more specifically how you are getting that result.
By writing you a test case, I saw what was wrong. Here is the one that
crashes:
Error reminder: TypeError: mapper() got an unexpected keyword argument
'order_by'
############## test_crash.py ##############
from sqlalchemy import *
from sqlalchemy.orm import *
meta = MetaData()
Session = scoped_session(sessionmaker(autoflush=False, transactional=False))
# Uncomment and comment this line for testing...
Session = Session()
mapper = Session.mapper
engine = create_engine('sqlite://', echo=True)
meta.bind = engine
#Session.configure(bind=engine)
user_table = Table('users', meta,
Column('id', Integer, primary_key=True),
Column('email', Unicode(40), unique=True, nullable=False),
Column('password', Unicode(20), nullable=False),
)
meta.create_all()
class User(object):
pass
user_mapper = mapper(User, user_table, order_by=user_table.c.email)
############## test_crash.py ##############
And here is the one that works:
############## test_ok.py ##############
from sqlalchemy import *
from sqlalchemy.orm import *
meta = MetaData()
Session = scoped_session(sessionmaker(autoflush=False, transactional=False))
mapper = Session.mapper
# Uncomment and comment this line for testing...
Session = Session()
engine = create_engine('sqlite://', echo=True)
meta.bind = engine
#Session.configure(bind=engine)
user_table = Table('users', meta,
Column('id', Integer, primary_key=True),
Column('email', Unicode(40), unique=True, nullable=False),
Column('password', Unicode(20), nullable=False),
)
meta.create_all()
class User(object):
pass
user_mapper = mapper(User, user_table, order_by=user_table.c.email)
############## test_ok.py ##############
Basicly, it crashes when the mapper is taken from the Session object
*after* it got instantiated. It works fine before.
This is a note you can have to put in the "scoped_session" docs when
you'll be writing it. Or this is a bug you'll fix before writing the
docs. :)
Don't forget to answer my question: "What are the benefits of
instantiating a Session object ?". Actually, I just feel better working
*with* a instantiated object.
Regards,
Alex
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---