- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 TypeDecorator 进行 Json 提取,而另一个模型将其用于其列之一。我正在使用这个 TypeDecorator 存储 python 列表对象。
def process_bind_param(self, value, dialect):
# etc...
def process_result_value(self, value, dialect):
# THIS NEVER GETS CALLED!!
if value is not None:
return json.loads(value)
return value
当我在使用装饰器的模型中存储数据时,会适本地调用 bind_param。现在,我通过以下方式使用 TypeDecorator 从模型中提取模式:
table = Table(table_name, meta, autoload=True, autoload_with=sengine)
现在进行查询测试(有很多方法可以循环和提取):
for record in source.query(table).all():
print type(record.column_using_custom_type_list_object) == str
# returns true ... this should be false ... should be of type list
# json.loads() returns type list ???
print record.column_using_custom_type_list_object[some_index]
# naturally this prints a character in the string, not a cell
问题是在查询表、对象和列时未调用 process_result_value()。我假设 SQLAlchemy 反射处理依赖项?我是否在构造函数中遗漏了一些选项来传输需要自定义类型装饰器的元数据?
最佳答案
我不确定这是否是同一个问题,但我认为它的相关性足以让我在这里写下答案。
存储对象并尝试读取属性后,函数 process_result_value 没有被调用,因为对象被缓存了。 (在这里找到 http://comments.gmane.org/gmane.comp.python.sqlalchemy.user/11406 )
所以解决方案就是使对象无效。
session.expire(obj)
http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#refreshing-expiring
关于types - SQL Alchemy - 使用 TypeDecorator 进行模式提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18153618/
我在我的 postgresql 数据库中使用 xml,我需要一个自定义类型来处理 SQLAlchemy 中的 xml 数据。 所以我制作了 XMLType 类与 xml.etree 进行通信,但它并没
我最近遇到了一个问题,非常感谢任何见解。圣诞节前,我在 PerlMonks 上发布了一个类似的问题,并提供了一些关于从 MooseX::Declare ([http://www.perlmonks.o
我正在尝试向 ORM 类成员添加自定义方法,以使其处理与该成员相关的事情。试图跟随 documentation . class EnhDateTime(types.TypeDecorator):
我正在使用 TypeDecorator 进行 Json 提取,而另一个模型将其用于其列之一。我正在使用这个 TypeDecorator 存储 python 列表对象。 def process_bind
有没有一种方法可以让枚举类在创建新数据库时自动创建,就像标准枚举一样,但也可以将它连接到运行 process_bind_param< 的 TypeDecorator/? 第一个代码块创建了一个 Enu
以前,我能够使用 Reflect 元数据获取组件的元数据。现在元数据已移动到附加到组件的一些注释。 读取元数据 type['__annotations__'][0].selector 绝对是一个 ha
我为 sqlalchemy 定义了以下自定义类型: class EnumColumnType(TypeDecorator): impl = Integer def __init__(s
我的 models.py 文件有两个模型,User 和 Job。 每个作业都将关联多个用户。 一个用户可以与多个作业相关联。 我需要能够执行类似 job.getUsers() 的操作 --> 用户对象
这个错误已经发生一天多了,但我不知道为什么。 应用程序模块 import {NgModule} from "@angular/core"; import {BrowserModule} from "@
我是一名优秀的程序员,十分优秀!