【发布时间】:2011-06-29 08:04:16
【问题描述】:
我正在尝试将烧杯缓存与 SQLAlchemy 一起使用,但我收到了错误。
这是我的表定义。
class Post(Base):
....
....
user = relation(User, primaryjoin = User.id == id)
tags = relation('Tags', backref = 'posts')
class Tags(Base):
...
...
user = relation(User, primaryjoin = User.id == id)
post = relation(Post, primaryjoin = Post.id == id)
烧杯缓存可与除这些之外的其他 SQLAlchemy 类一起使用。
当我运行程序时,我收到以下错误;
DetachedInstanceError: Parent instance <Post at 0x101f90b10> is not bound to a Session; lazy load operation of attribute 'user' cannot proceed.
我在 StackOverFlow 上进行了搜索,并在另一个线程中发现我需要禁用延迟加载,因此我更改了行
user = relation(User, primaryjoin = User.id == id)
到
user = relation(User, primaryjoin = User.id == id, lazy='dynamic')
但这会发生在模板中的以下错误(post.user.fullname);
AttributeError: 'AppenderQuery' object has no attribute 'fullname'
我做错了什么?
【问题讨论】:
标签: python caching sqlalchemy beaker