orig_cache_key = orig_query._generate_cache_key()
replacement_cache_key = context.query._generate_cache_key()
+ if replacement_cache_key is not None:
assert orig_cache_key is not None
- assert replacement_cache_key is not None
- opt._extra_criteria = tuple(
- replacement_cache_key._apply_params_to_element(
- orig_cache_key, crit
+ opt._extra_criteria = tuple(
+ replacement_cache_key._apply_params_to_element(
+ orig_cache_key, crit
+ )
+ for crit in opt._extra_criteria
)
- for crit in opt._extra_criteria
- )
return opt
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import testing
+from sqlalchemy import TypeDecorator
from sqlalchemy import union_all
from sqlalchemy import util
from sqlalchemy.orm import aliased
c_expr = query_expression(literal(1))
+ class CustomTimeStamp(TypeDecorator):
+ cache_ok = False
+ impl = Integer
+
+ class HasNonCacheable(ComparableEntity, Base):
+ __tablename__ = "non_cacheable"
+
+ id = Column(Integer, primary_key=True)
+ created = Column(CustomTimeStamp)
+ msg_translated = query_expression()
+
@classmethod
def insert_data(cls, connection):
A, A_default, B, C = cls.classes("A", "A_default", "B", "C")
+ (HasNonCacheable,) = cls.classes("HasNonCacheable")
s = Session(connection)
s.add_all(
C(id=2, x=2),
A_default(id=1, x=1, y=2),
A_default(id=2, x=2, y=3),
+ HasNonCacheable(id=1, created=12345),
]
)
)
eq_(c2.all(), [C(c_expr=4)])
+ def test_non_cacheable_expr(self):
+ """test #10990"""
+
+ HasNonCacheable = self.classes.HasNonCacheable
+
+ for i in range(3):
+ s = fixture_session()
+
+ stmt = (
+ select(HasNonCacheable)
+ .where(HasNonCacheable.created > 10)
+ .options(
+ with_expression(
+ HasNonCacheable.msg_translated,
+ HasNonCacheable.created + 10,
+ )
+ )
+ )
+
+ eq_(
+ s.scalars(stmt).all(),
+ [HasNonCacheable(id=1, created=12345, msg_translated=12355)],
+ )
+
def test_reuse_expr(self):
A = self.classes.A