SQLAlchemy bug(?)触发“(ProgrammingError)表名[...]多次指定”

时间:2014-08-04 05:33:23

标签: python postgresql sqlalchemy

SQLAlchemy(0.8.7和0.9.7)正在为Postgresql 9.3生成错误的SQL,我怀疑它是一个错误,但我还没有足够的信心来解除用户错误。

以下是我的测试用例代码的片段。

    print "--- Snip Start ---"
    print "target_table", self.target_table
    print "update_where_binding", update_where_binding
    print "update_values_binding", update_values_binding
    table_update = (
        self.target_table.update(
            whereclause=update_where_binding, values=update_values_binding)
    )

    print "Query", table_update

    print "Data", updates
    print "Starting query"
    self.session.execute(
            table_update, updates)
    print "Completed query"
    print "--- Snip End ---"

结果如下。

--- Snip Start ---
target_table Dummy
update_where_binding "Dummy".pa_name = :b_pa_name
update_values_binding {'pa_name_hash': BindParameter('pa_name_hash', None, type_=NullType())}
Query UPDATE "Dummy" SET pa_name_hash=%(pa_name_hash)s FROM "Dummy" WHERE "Dummy".pa_name = %(b_pa_name)s

(我只是插入这里说 - 看!错误已经发生。FROM "Dummy"部分是无关紧要的,因为表名已经作为查询的第二个单词出现了。但是继续现在......)

Data [{'b_pa_name': '5', 'pa_name_hash': 'x'}, {'b_pa_name': '6', 'pa_name_hash': 'y'}]
Starting query

Traceback (most recent call last):
[...]
ProgrammingError: (ProgrammingError) table name "Dummy" specified more than once
 'UPDATE "Dummy" SET pa_name_hash=%(pa_name_hash)s FROM "Dummy" WHERE "Dummy".pa_name = %(b_pa_name)s' ({'b_pa_name': '5', 'pa_name_hash': 'x'}, {'b_pa_name': '6', 'pa_name_hash': 'y'})

这看起来像SQLAlchemy中的错误,或者是否有其他解释?

0 个答案:

没有答案