Skip to content

[objectql] 字段 defaultValue 语义:显式 null 不回填、解析晚于 hook、表单不预填 current_user #2706

Description

@baozhoutao

概述

想实现「新建记录时某人员字段默认当前用户」,用 Field.user({ defaultValue: 'current_user' }) 遇到三个叠加问题:

  1. 解析顺序晚于 beforeInsert hook —— hook 读到 null,派生字段算错。
    定位:packages/objectql/src/engine.ts:2143(hook)先于 :2181(applyFieldDefaults)。(= chore(deps)(deps-dev): bump @vitest/coverage-v8 from 2.1.9 to 4.0.17 #29)
  2. 只在「省略」时回填,显式 null 不回填 —— body 不含该字段 → 回填当前用户 ✅;body 显式 field: null不回填,落库 null ❌。
    定位:packages/objectql/src/engine.ts:802(判据 !== undefined)。
  3. 创建表单不预填动态令牌 —— current_user / {current_user_id} 均不被解析成真实用户预填(停在「选择...」);静态默认(如 status:'planned')能预填。
    定位:objectui plugin-form/src/ObjectForm.tsx:702-712(原样拷贝 defaultValue,无令牌解析)。此子项归属 objectui,在本 issue 交叉引用,建议 objectui 侧同步跟进。

期望

  • 服务端 defaultValue 对「显式 null」也回填(与「省略」一致),或文档化差异;
  • 解析顺序前移到 beforeInsert hook 之前;
  • (objectui)创建表单支持解析 current_user/{current_user_id} 预填用户字段。

规避

beforeInsert hook 读 ctx.session.userId 兜底回填。


来源(项目 dogfood):steedos-labs/os-tianshun-mtc#31 · 含 #29

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions