【问题标题】:Second insert not working, but first and third are第二个插入不起作用,但第一个和第三个是
【发布时间】:2019-10-15 05:07:28
【问题描述】:

我有三个使用 psycopg2 运行的 EXECUTE 语句。更新后第一个 INSERT 可见,第三个 INSERT 可见,但第二个 INSERT 未发生。

OpenERP 为我的函数提供了一个打开的游标,我将其用于所有三个语句; OpenERP 然后在我的函数返回后提交。我试图捕捉任何异常(没有),我尝试使用调试打印来寻找线索(没有)——有什么想法吗?以下是声明。

作品:

    cr.execute("""\
        INSERT INTO ir_act_report_xml
            (
              id, header, report_type, type, model, name, report_name,
              create_uid, create_date, write_uid, write_date,
              auto, multi, attachment_use
               )
        VALUES
            (
              %s, 't', 'pdf', 'ir.actions.report.xml', '%s', '%s', '%s',
              1, now() AT TIME ZONE 'UTC', 1, now() AT TIME ZONE 'UTC',
              false, false, false
              )
            """
            % (action_id, model_name, title_name, report_xml_id)
              )

不起作用,没有给出错误

    cr.execute("""\
        INSERT INTO ir_model_data
            (
            module, name, model, res_id, date_init, date_update,
            create_uid, create_date, write_uid, write_date,
            noupdate
            )
        VALUES
            (
              '%s', '%s', '%s', %s, now() AT TIME ZONE 'UTC', now() AT TIME ZONE 'UTC',
              1, now() AT TIME ZONE 'UTC', 1, now() AT TIME ZONE 'UTC',
              false
              )
            """
            % (module, imd_xml_id, model_name, action_id)
            )

作品:

    cr.execute("""\
        INSERT INTO ir_values
            (
              id, key, key2, value, model, name, res_id,
              create_uid, create_date, write_uid, write_date
              )
        VALUES
            (
              %s, 'action', 'client_print_multi', 'ir.actions.report.xml,%s', '%s', '%s', 0,
              1, now() AT TIME ZONE 'UTC', 1, now() AT TIME ZONE 'UTC'
              )
            """
            % (iv_id, action_id, model_name, title_name),
            )

这三个都是连续处理的,没有介入提交或回滚。

【问题讨论】:

    标签: python postgresql odoo psycopg2


    【解决方案1】:

    要跟踪此类问题,请检查数据库上实际发生的情况。

    在运行 SQL 语句之前将 log_min_duration_statement 设置为 0,然后检查 PostgreSQL 日志文件。然后你就知道实际执行了哪些语句。

    对此类行为的可能解释:

    • 三个INSERTs 在不同的数据库会话上执行。

    • 失败的语句甚至没有进入数据库,异常被 Python 捕获。

    • 你的事务管理和你想的不一样,回滚了一条语句。

    【讨论】:

    • 日志记录的建议得到了回报——后来 OpenERP 正在删除我的条目!
    猜你喜欢
    • 1970-01-01
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多