Skip to content

[Bug]: InvenTree correlated inventory SUM query panics in ColumnExpressionExecutor.Eval #29926

Closed

Description

@dengn

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

v4.2.5

Commit ID

1a44f3d

Other Environment Information

SELECT VERSION(): 8.0.30-MatrixOne-v4.2.5
Application: InvenTree 1.5.7
InvenTree commit: 2ca0d0e55b08e138342b20fccfa8307fad25a02c
Django: 5.2.16
Deployment: isolated local environment, using the MySQL protocol.

Actual Behavior

After completing InvenTree’s native database migrations, creating a part and a stock item through its authenticated native API succeeds.
Reading the part subsequently returns HTTP 500. Isolating the native Django ORM annotations shows that the in_stock correlated aggregate returns SQL error 20101, containing this recovered Go panic:

internal error: panic runtime error: index out of range [10] with length 9:

runtime.panicBounds64
/opt/hostedtoolcache/go/1.26.4/x64/src/runtime/panic.go:236
runtime.panicBounds
/opt/hostedtoolcache/go/1.26.4/x64/src/runtime/asm_amd64.s:2129
github.com/matrixorigin/matrixone/pkg/sql/colexec.(*ColumnExpressionExecutor).Eval
/home/runner/work/matrixone/matrixone/pkg/sql/colexec/evalExpression.go:1194
github.com/matrixorigin/matrixone/pkg/sql/colexec.(*FunctionExpressionExecutor).Eval
The error returned over the MySQL protocol truncates the remaining stack trace.

Expected Behavior

Expected behavior
For the described fixture, the query should return:
id | in_stock
40002 | 23.12500
This expected result follows from the fixture’s stock quantity and the query predicates; a separate MySQL comparison has not yet been performed.
The query should not produce an executor panic.
Impact and observations

  • Blocks the native InvenTree part detail workflow; part GET and PATCH requests returned HTTP 500.
  • An independently isolated external_stock annotation also returned the same bounds-panic signature.
  • Other queries continued to execute after the error. A MatrixOne process crash was not observed.
  • The separate 20102 non-equality correlated aggregate rejection and 1064 column-remapping error are additional observations and are not included as this panic’s root cause.
  • The confirmed panic location is ColumnExpressionExecutor.Eval. The underlying planner or executor defect, and whether the outer category join is necessary to trigger it, remain unconfirmed.

Steps to Reproduce

Reproduction context
This was observed against the migrated InvenTree schema, with:
- Part ID: 40002
- Stock item belonging to this part
- Stock quantity: 23.12500
- Stock status: 10
- is_building = 0
- belongs_to_id, consumed_by_id, customer_id and sales_order_id all NULL
The complete failing statement below was extracted from the native Django ORM query, with its bound parameters substituted.
A standalone minimal DDL reproducer has not yet been verified. The statement requires the corresponding InvenTree tables and fixture data.
Complete failing SQL
SELECT
    `part_part`.`id` AS `id`,
    COALESCE(
        (
            SELECT SUM(U0.`quantity`) AS `aggregation`
            FROM `stock_stockitem` U0
            WHERE (
                U0.`belongs_to_id` IS NULL
                AND U0.`consumed_by_id` IS NULL
                AND U0.`customer_id` IS NULL
                AND U0.`is_building` = 0
                AND U0.`quantity` > 0
                AND U0.`sales_order_id` IS NULL
                AND U0.`status` IN (10, 50, 55, 85)
                AND U0.`part_id` = (`part_part`.`id`)
            )
            GROUP BY U0.`part_id`
            ORDER BY NULL
        ),
        0
    ) AS `in_stock`
FROM `part_part`
LEFT OUTER JOIN `part_partcategory`
    ON (`part_part`.`category_id` = `part_partcategory`.`id`)
WHERE `part_part`.`id` = 40002
ORDER BY
    `part_part`.`tree_id` ASC,
    `part_part`.`lft` ASC
LIMIT 1;

Additional information

No response

Activity

  1. added
    kind/bug
    on Oct 12, 2026
  2. XuPeng-SH commented on Oct 13, 2026

    @XuPeng-SH
    Contributor

    Verification on current main 3e50e1b32d

    Verified source revision: 3e50e1b32d8da61bbbf70c89989fb08b671809de. Upstream main was checked again after execution and still resolved to this SHA.

    Environment: Linux amd64, Go 1.27.1, fresh matching CPU CGo libraries, the repository's canonical embedded one-CN SQL fixture, GOMAXPROCS=2, and fresh owned schemas. This used the actual MySQL frontend and engine. Embedded tests leave release/version strings at development defaults; source/build provenance establishes the tested revision, rather than a release VERSION() string. All test schemas and owned temporary resources were cleaned up.

    Result: original correlated SQL and native schema shape pass

    Executed the complete SQL from this issue, retaining the four native tables' column order, types, and indexes from the earlier captured SHOW CREATE fixture. Restored all 11 native FK edges whose referenced tables are inside that four-table fixture; FKs to unrelated application tables remain outside the fixture.

    The original query returned:

    id    | in_stock
    40002 | 23.12500
    

    No ColumnExpressionExecutor.Eval bounds panic occurred. Additional checks passed:

    • The captured external_stock annotation returned its expected zero for the retained non-external location.
    • PREPARE/EXECUTE returned the same original result.
    • Zero eligible quantity returned COALESCE's zero.
    • An additional eligible stock row of 1.87500 produced 25.00000.
    • Making that additional row belong to another retained stock item excluded it and restored 23.12500.
    • A NULL outer category retained the part and the correct correlated sum.

    Disposition: the original SQL and tested native database shape no longer reproduce the panic on main. This is stronger than the earlier reduced-column fixture, but does not claim a complete migrated InvenTree schema or authenticated GET/PATCH workflow was run. The full application workflow was excluded following the requester's clarification. No new production patch is justified by this reproducer.

  3. Ariznawlll commented on Oct 13, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:21f19ae06305ca2acd253d15123f851899d6b6a1
    • 部署方式:本地从该 SHA 构建的独立 1 LOG / 1 TN / 1 CN MatrixOne,MySQL 协议连接;另结合此前在 3e50e1b32d8da61bbbf70c89989fb08b671809de 对保留原生列顺序、类型、索引及 11 条夹具内外键的四表 SQL 验证
    • 测试日期:2026-10-13

    原问题验证

    在当前 main 上执行 issue 中的 part_part / part_partcategory / stock_stockitem 关联库存聚合 SQL,保留 COALESCE、关联 SUM、GROUP BY、ORDER BY NULL、LEFT JOIN 和外层排序/限制。目标 part 40002 连续 3 轮返回 in_stock=23.12500,无 ColumnExpressionExecutor.Eval 越界 panic。此前更接近 InvenTree 原生四表结构的原 SQL 也返回相同值,见下方已有验证记录。

    Happy Path 覆盖

    1. 原 SQL 连续 3 轮精确返回 (40002, 23.12500);每轮源表 3 行、数量总和 129.12500 不变。
    2. 无合格库存时现有 part 返回 0.00000;增加一条合格库存后返回 25.00000。
    3. 将新增库存标记为属于另一库存项后恢复 23.12500;外层分类为空时 LEFT JOIN 仍保留目标 part 和正确库存总和。

    Unhappy Path 覆盖

    1. 故意查询不存在的列,语句被拒绝;随后同一连接再次执行原 SQL,仍返回 (40002, 23.12500),源数据未被破坏。

    白盒验证

    本问题以实际 SQL 执行器行为验收;本次没有新增内部故障注入或 -race,它们无法替代原 SQL 的结果与无 panic 检查。

    回归测试

    • 新增 MOTR #234 的 script/14_issue_regression/issue_29926_inventree_correlated_sum.py 及对应 .out。在当前 main 的独立实例上运行 ./motr --repeat 3 14_issue_regression.issue_29926_inventree_correlated_sum,3/3 success、0 failed、0 skipped;脚本内部的原查询也每次重复 3 轮。与 golden 对照 3/3 一致,用例数据库已清理。
    • 此问题是确定性的关联 SQL/panic 回归,不需要 big-data 或 chaos。MOTR PR 尚待评审合入;其当前 head 的四项离线工具检查全部通过。
    • 按此前澄清,本次关闭范围是原 SQL 和其数据库形态,不声称运行了 InvenTree 1.5.7 的完整迁移及经认证的 GET/PATCH HTTP 流程。新 MOTR 夹具是精简 SQL 回归,不等同完整应用部署。

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions