fix(objectql,spec,rest): #2922 import automation chain — per-row batch hooks, effective skipAutomations, run-automations default ON#2941
Merged
Conversation
…h hooks, effective skipAutomations, run-automations default ON - engine.insert now triggers beforeInsert/afterInsert once per row with single-record hook contexts, so flat-input proxies, declarative hook conditions, audit writers and record-change triggers see real records instead of arrays. - New ExecutionContext.skipAutomations (mirrored into HookContext.session) suppresses metadata-bound automation hooks and implies skipTriggers for flow dispatch; code-registered system hooks (audit, security, sharing) still run. Makes the import wizard checkbox and import undo effective. - REST import defaults runAutomations to true unless the request explicitly opts out, matching historical behavior. Closes #2922
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckThis PR changes 3 package(s): 102 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the three platform-level defects in the data-import chain reported in #2922.
1. Batch inserts fired hooks once with array-shaped contexts
engine.insert(object, records[])triggeredbeforeInsert/afterInserta single time withctx.input.data/ctx.resultas arrays, breakinginstallFlatInput(flat proxy readsundefined),pickRecordPayload(declarative conditions evaluated against an array), plugin-audit'swriteAudit(after?.idundefined,{...after}spreads an array), andtrigger-record-change'sbuildContext.Fix:
engine.insertnow builds one single-recordHookContextper row and triggersbeforeInsert/afterInsertper row. Per-row hook mutations (data replacement included) flow through to the driver; autonumber/encryption/normalization/validation run per row; batch driver path (bulkCreateor per-row fallback) unchanged in shape. Return value semantics preserved: array for batch, single record otherwise, both boolean-coerced after-views.2.
skipAutomationswas written but never readThe import runner (
import-runner.ts) and the import-undo route wroteskipAutomationsinto the execution context, but the engine ignored it — the "运行自动化与触发器" checkbox was a no-op, and undo re-fired automation.Fix:
ExecutionContext.skipAutomations+HookContext.session.skipAutomations(Zod-first, documented).buildSessionpasses it through and impliesskipTriggers(reusing the existing flow-dispatch suppression gate inRecordChangeTrigger).triggerHooksskips metadata-bound hooks (HookEntry.metapresent, i.e. registered viabindHooksToEngine) when the flag is set. Code-registered system hooks — audit, capability gates, sharing projection — carry nometaand still run: the flag never bypasses security or audit.3. Default flipped to run automations
prepareImportRequestnow defaultsrunAutomations = body?.runAutomations !== false. Automations always ran historically (the engine ignored the flag until this PR), so opt-out must be explicit. Companion objectui PR flips the ImportWizard checkbox default to checked.Tests
bulkCreatepairing) andskipAutomations(meta hooks skipped, system hooks run, session getsskipTriggers).runAutomationsdefault suite; required-field pre-check tests updated to opt out explicitly (that path only runs with automations off).pnpm test: 128/129 tasks pass; the one failure (semantic-roles.dogfood.test.ts) is abeforeAllstack-boot timeout under full-suite parallel load and passes in isolation (3.8s) — unrelated to this change.Changeset included (patch: spec / objectql / rest).
Closes #2922