Skip to content

TypeDecorator is creating a cache key from user args, should disable caching in this case #6436

@zzzeek

Description

@zzzeek

it's not safe to assume cache key status for any arguments passed to TypeDecorator and I wonder why the arguments here are even necessary to be part of a cache key. propose a simple flag cache_ok for TypeDecorator w/ a warning and NO_CACHE when not set.

from sqlalchemy import Column, Integer, create_engine, TypeDecorator, Unicode
from sqlalchemy.orm import sessionmaker, as_declarative, declared_attr


class AltType(TypeDecorator):
    impl = Unicode(255)

    def __init__(self, choices):
        self.choices = choices
        super(AltType, self).__init__()


@as_declarative()
class Base(object):
    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    pk = Column(Integer, primary_key=True)


class MyClass(Base):
    d = Column(AltType(['a', 'list', 'here']))


if __name__ == '__main__':
    e = create_engine('sqlite://', echo=True)
    conn = e.connect()

    Base.metadata.create_all(e)

    s = sessionmaker(e)()
    q = s.query(MyClass).filter(MyClass.d == 'search_str')

    result = q.first()  # <---- error here
    print(result)

Metadata

Metadata

Assignees

No one assigned

    Labels

    datatypesthings to do with database types, like VARCHAR and othersregressionsomething worked and was broken by a changestatement caching

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions