I realize I'm doing something hacky, but I'm wondering if this is the
expected behavior. The issue is that if I modify the modifier on a
UnaryExpression, even if I clone the Query ahead of time it modifies
other Query instances. See the following:
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import *
from sqlalchemy.sql import operators
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite://')
Session = sessionmaker(bind=engine, autoflush=True, autocommit=False)
session = Session()
Base = declarative_base(engine=engine)
class Category(Base):
__tablename__ = 'foo_category'
id = Column('id', Integer, primary_key=True)
name = Column('name', String(50))
created_at = Column('created_at', DateTime, nullable=True,
onupdate=datetime.datetime.now)
def __repr__(self):
return self.name
Base.metadata.create_all()
session.add_all([Category(name='zzeek'),
Category(name='jek'),
Category(name='empty')])
# order ascending
c1 = session.query(Category).order_by(asc(Category.name))
assert [u'empty', u'jek', u'zzeek'] == [c.name for c in c1]
# clone the query and verify still asc
c2 = c1._clone()
assert [u'empty', u'jek', u'zzeek'] == [c.name for c in c2]
# reverse the order_by modifier on c1
c1._order_by[0].modifier = operators.desc_op
assert [u'zzeek', u'jek', u'empty'] == [c.name for c in c1]
# here's the problem, c2 is now modified
assert [u'zzeek', u'jek', u'empty'] == [c.name for c in c2]
Michael Trier
blog.michaeltrier.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---