(via EnkiP): fix(workflow-executor): restore field names in fetchXToOneCandidate befo#1611
Conversation
2799340 to
7b222de
Compare
| if (!packedId) { | ||
| throw new RelatedRecordNotFoundError(target.selectedRecordRef.collectionName, target.name); |
There was a problem hiding this comment.
🟡 Medium executors/load-related-record-step-executor.ts:317
In fetchXToOneCandidate, the nested relation object's field names are not restored using the related collection's schema, causing extractReferenceFieldValue to return null for reference fields with non-camelCase names (e.g., full_name). At line 316-319, restoreFieldNames is called with sourceSchema.fields (the parent collection), but the nested relation object contains fields from the related collection. When the agent's JSON:API serializer returns fullName (camelCased), but referenceField is full_name, the lookup relation[referenceField] returns undefined. Consider using relatedSchema.fields for restoration before extracting the reference field value.
- const relation = restoredValues[target.name] as Record<string, unknown> | null | undefined;
- const packedId = relation?.id as string | undefined;
+ const relation = restoredValues[target.name] as Record<string, unknown> | null | undefined;
+ const relatedSchema = await this.getCollectionSchema(target.relatedCollectionName);
+ const restoredRelation = relation
+ ? restoreFieldNames(
+ relation,
+ relatedSchema.fields.map(f => f.fieldName),
+ )
+ : null;
+ const packedId = restoredRelation?.id as string | undefined;🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file packages/workflow-executor/src/executors/load-related-record-step-executor.ts around lines 317-318:
In `fetchXToOneCandidate`, the nested relation object's field names are not restored using the related collection's schema, causing `extractReferenceFieldValue` to return `null` for reference fields with non-camelCase names (e.g., `full_name`). At line 316-319, `restoreFieldNames` is called with `sourceSchema.fields` (the parent collection), but the nested `relation` object contains fields from the related collection. When the agent's JSON:API serializer returns `fullName` (camelCased), but `referenceField` is `full_name`, the lookup `relation[referenceField]` returns `undefined`. Consider using `relatedSchema.fields` for restoration before extracting the reference field value.
Evidence trail:
packages/workflow-executor/src/executors/load-related-record-step-executor.ts lines 279-327 (fetchXToOneCandidate), lines 308-312 (restoreFieldNames with sourceSchema.fields), line 314 (nested relation extraction), lines 323-324 (extractReferenceFieldValue with referenceField from relatedSchema).
packages/workflow-executor/src/adapters/agent-client-agent-port.ts lines 28-42 (restoreFieldNames implementation: only operates on top-level keys), line 90 (getRecord's restoreFieldNames with projection fields).
packages/workflow-executor/src/executors/load-related-record-step-executor.ts lines 482-486 (fetchRelatedData correctly uses relatedSchema.fields for restoreFieldNames — the correct pattern).
Summary
Fixes an issue where relations with underscores in their names (e.g.,
customer_order) would trigger spuriousRelatedRecordNotFoundErrorwhen accessing them in the workflow executor.Changes
restoreFieldNamesinfetchXToOneCandidateafter retrieving the parent record fromagentPort.getRecordRoot Cause
The agent-client returns records with camelCase keys, but relation lookups were using the original field names (which may contain underscores). Without restoring the field names first, the relation key wouldn't match and the lookup would fail.
Note
Macroscope: Fix It For Me
Activity
Currently: Not merged: unstable
Previously
Note
Fix field name restoration in
fetchXToOneCandidatefor BelongsTo/HasOne relationsagentPort.getRecord, rather than querying viagetRelatedData.fetchXToOneCandidateandfetchRelatedDatamethods inload-related-record-step-executor.tsto restore original field names and build correctrecordIdarrays using the related schema's declared primary key fields.LoadRelatedRecordPendingDatato useavailableFields,suggestedField,availableRecordIds(with optionalreferenceFieldValue), andsuggestedRecordinstead of the previous flatdisplayName/name/selectedRecordIdshape.pending-data-validators.tswhere onlyfieldDisplayNameis provided (nouserConfirmed), triggering a candidate refresh without confirmation.AgentClientAgentPort.getRelatedDatato return raw rows (Record<string, unknown>[]) and moves field name restoration responsibility to the executor.LoadRelatedRecordPendingDatashape is a breaking change for any clients reading or writing that structure.📊 Macroscope summarized eb2e978. 6 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.