Skip to content

Fix: Flex field with object value threw an error#119

Open
aguspdana wants to merge 6 commits intomainfrom
agus/add-test
Open

Fix: Flex field with object value threw an error#119
aguspdana wants to merge 6 commits intomainfrom
agus/add-test

Conversation

@aguspdana
Copy link
Collaborator

@aguspdana aguspdana commented Feb 12, 2026

We should be able to set object value for a FLEX field. But currently it throws an error.

In the monorepo it threw this error:

ror: [Internal] This object has not been initiated with a $thing: {"category":"SCOPE","action":"SUBMIT"}
    at file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:39886
    at _traverse (/Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/object-traversal@1.0.1/node_modules/object-traversal/dist/object-traversal.cjs.development.js:183:9)
    at traverse (/Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/object-traversal@1.0.1/node_modules/object-traversal/dist/object-traversal.cjs.development.js:147:3)
    at file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:39439
    at Immer2.produce (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/immer@10.1.1/node_modules/immer/dist/immer.mjs:571:20)
    at $r (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:39426)
    at Object.rc (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:154:5167)
    at Object.enter (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:15114)
    at tr (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:16321)
    at Ds (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:16458)
    at Object.send (file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:16536)
    at file:///Users/aguspdana/Projects/blitz/blitz_4/node_modules/.pnpm/@blitznocode+blitz-orm@0.15.0_tslib@2.8.1_typescript@5.9.3_ws@8.19.0/node_modules/@blitznocode/blitz-orm/dist/index.mjs:93:15268
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) 
 POST /api/builder/mutate 500 in 72ms (compile: 1923µs, proxy.ts: 4ms, render: 66ms)

In the new BORM test it throws this error:

Error: [Wrong format] The field $thing is required in refFields
❯ src/stateMachine/mutation/bql/enrichSteps/enrichChildren.ts:41:15
    39| 
    40|       if (!subNode.$thing) {
    41|         throw new Error('[Wrong format] The field $thing is required in refFields');
      |               ^
    42|       }
    43|       return { ...subNode, $op, $bzId };
❯ Module.enrichChildren src/stateMachine/mutation/bql/enrichSteps/enrichChildren.ts:22:73
❯ callback src/stateMachine/mutation/bql/enrich.ts:170:13
❯ _traverse node_modules/.pnpm/object-traversal@1.0.1/node_modules/object-traversal/src/traverse.ts:91:9
❯ Proxy.traverse node_modules/.pnpm/object-traversal@1.0.1/node_modules/object-traversal/src/traverse.ts:52:3
❯ src/stateMachine/mutation/bql/enrich.ts:62:5
❯ Module.Immer2.produce node_modules/.pnpm/immer@10.1.1/node_modules/immer/src/core/immerClass.ts:97:14
❯ Module.enrichBQLMutation src/stateMachine/mutation/bql/enrich.ts:61:18
❯ Object.enrich src/stateMachine/mutation/mutationMachine.ts:99:7

Summary by cubic

Fixes errors when storing plain objects and nested arrays in FLEX ref fields. FlexRefRel.flexReferences now accepts objects and arrays-of-objects, and values round-trip correctly.

  • Bug Fixes

    • Mark FLEX data objects with FlexDataValue and skip $thing/$op checks in enrichment (handles nested arrays).
    • SURQL build flattens only $-refs; keeps data arrays/objects intact.
    • SurrealDB parsing serializes FLEX objects via JSON.stringify.
    • Add tests fl8 and fl9 for object and array-of-objects in flexReferences.
  • Dependencies

    • Bump package to 0.15.4 and upgrade pnpm to 10.30.0.

Written for commit 1289b86. Summary will update on new commits.


Important

Adds a test in refFields.ts to verify FLEX fields can accept object values without errors.

  • Test Addition:
    • Adds test fl8:[flex, object] in refFields.ts to verify that flexReferences can accept objects.
    • Ensures that objects in flexReferences do not trigger errors related to $thing or refFields.
  • Behavior:
    • Confirms that flexReferences can store objects like { msg: 'Hello, world!' } without errors.
    • Validates the query result matches the input object structure.
  • Cleanup:
    • Includes cleanup logic to delete test data after execution to maintain test isolation.

This description was created by Ellipsis for 1538075. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 1538075 in 19 seconds. Click for details.
  • Reviewed 44 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_LUsSkldzNAHqw7OD

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@aguspdana aguspdana changed the title Add test: Flex field with object value Fix: Flex field with object value threw an error Feb 13, 2026
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/stateMachine/mutation/surql/build.ts">

<violation number="1" location="src/stateMachine/mutation/surql/build.ts:332">
P2: Non-variable FLEX values are inserted into the SurQL array without serialization, so object values will stringify to "[object Object]" (and plain strings become unquoted identifiers). Use the FLEX serializer (e.g., parseFlexValSurrealDB) for non-$ elements before joining so object values are preserved.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}
return el;
});
return `${rf} = [${processedElements.join(', ')}]`;
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Non-variable FLEX values are inserted into the SurQL array without serialization, so object values will stringify to "[object Object]" (and plain strings become unquoted identifiers). Use the FLEX serializer (e.g., parseFlexValSurrealDB) for non-$ elements before joining so object values are preserved.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/stateMachine/mutation/surql/build.ts, line 332:

<comment>Non-variable FLEX values are inserted into the SurQL array without serialization, so object values will stringify to "[object Object]" (and plain strings become unquoted identifiers). Use the FLEX serializer (e.g., parseFlexValSurrealDB) for non-$ elements before joining so object values are preserved.</comment>

<file context>
@@ -317,7 +317,19 @@ export const buildSURQLMutation = async (flat: FlatBqlMutation, schema: Enriched
+          }
+          return el;
+        });
+        return `${rf} = [${processedElements.join(', ')}]`;
       }
 
</file context>
Fix with Cubic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aguspdana wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block[rf] is either a string or a string array. Example of block:

{
  '$thingType': 'relation',
  '$op': 'replace',
  '$bzId': 'R_5WUuSigSeWgZOENaOlbnV',
  '$thing': 'FlexRefRel',
  flexReferences: [ '{"msg":"Hello, world!"}' ],
  [Symbol(stepPrint)]: Set(1) { 'clean' }
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I've saved this as a new learning to improve future reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants