Skip to content

fix(mongodb): keep ObjectId type through Find store then Load copy - #204

Merged
Malaydewangan09 merged 6 commits into
kestra-io:mainfrom
Varshith-Kali:fix-193-find-store-objectid-roundtrip
Nov 3, 2026
Merged

Malaydewangan09 merged 6 commits into
kestra-io:mainfrom
Varshith-Kali:fix-193-find-store-objectid-roundtrip

Conversation

@Varshith-Kali

@Varshith-Kali Varshith-Kali commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #193

A Find with store: true wrote ObjectIds as bare hex strings, so a Load of that file inserted them back as strings and the copy lost the ObjectId type.

Find, Aggregate and Trigger get an objectIdFormat property. HEX (default) keeps the current output, so rows[0]._id is still a hex string and existing flows are unchanged. EXTENDED_JSON writes ObjectIds as {"$oid": "..."}, which Load turns back into ObjectIds, so Find store: true then Load keeps the type, nested and array values included.

Tests run against MongoDB: BsonTypesTest.findStoreThenLoadKeepsObjectIds covers the round trip, plus EXTENDED_JSON cases for Aggregate and Trigger, and the default HEX output is asserted unchanged for all three.

MongoDbService.map() returned a bare hex string for OBJECT_ID while every other type without a JSON equivalent was wrapped in Extended JSON. Load decodes only wrapper maps, so a bare hex string loaded back as a String and the copy stopped matching the source under BSON type-aware equality: $lookup, ObjectId equality filters and {$type: "objectId"} all returned nothing, while both tasks reported SUCCESS.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@github-project-automation github-project-automation Bot moved this to To review in Pull Requests Oct 27, 2026
@kestrabot kestrabot Bot added area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors labels Oct 27, 2026
@kestrabot
kestrabot Bot requested review from a team and Malaydewangan09 October 27, 2026 09:58
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Hi maintainers, this PR is ready for review. The CI run is parked at the first-time-contributor approval gate (0 check runs so far); could someone please approve the run when convenient? Thanks.

The Trigger reuses Find, so its rows now carry ObjectIds as $oid wrappers, the same form this PR already gives Find rows. Three TriggerWatermarkTest assertions still pinned the old bare hex string form, which is what CI failed on (3 failed, 134 passed). The watermark internals are untouched: the stored position still holds the raw ObjectId, as the passing storedPosition assertion shows.
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

CI on 43a4b2d failed in 3 TriggerWatermarkTest assertions (134 passed, 3 failed). The Trigger reuses Find, so its rows now carry ObjectIds as $oid wrappers, the same form this PR gives Find rows. The 3 assertions still pinned the old bare hex string form, so I updated them in 83bc015. The watermark internals are untouched: the stored position still holds the raw ObjectId, as the passing storedPosition assertion shows. Waiting on the rerun to confirm green.

@Malaydewangan09 Malaydewangan09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the fix works, I ran the full suite against MongoDB and the copy now keeps every ObjectId. The catch is that it changes _id from a hex string to {"$oid": ...} in every Find, Aggregate and Trigger output, which breaks flows reading rows[0]._id. Could you keep hex as the default and add an opt-in property (e.g. objectIdFormat: HEX | EXTENDED_JSON) that uses the $oid form?

… opt-in

Hex stays the default, so flows reading rows[0]._id keep working. Find, Aggregate and Trigger take objectIdFormat (HEX or EXTENDED_JSON); EXTENDED_JSON keeps the $oid form, so Find with store: true followed by Load still keeps ObjectIds. Both review nits are in: the map comment is a single short line, and the CrudTest assertion uses getFirst().

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Thanks for running the full suite against MongoDB and catching the output change, you are right that breaking rows[0]._id is worse than the default fix. Done in the latest push: hex is the default again, and Find, Aggregate and Trigger now take objectIdFormat with HEX and EXTENDED_JSON. EXTENDED_JSON keeps the $oid form, so a Find with store: true followed by Load still keeps ObjectIds, and the store and fetch paths on both tasks plus the Trigger pass-through all use it. The two nits are in as well. Let me know if the property should live anywhere else, or if you want the default documented anywhere beyond the property description.

@Malaydewangan09 Malaydewangan09 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, the default output now matches main and the copy keeps every ObjectId, the tests pass here. It conflicts with main though: #208 added new map() callers in Find and Aggregate, and main has a new BINARY case next to the moved OBJECT_ID one. Could you merge main? A few small things inline, plus an Aggregate test with EXTENDED_JSON and IdUtils.create() for the ids in the new Trigger test.

Could you also add a screenshot of a Find with store: true then Load keeping the ObjectId?

…objectid-roundtrip

# Conflicts:
#	src/main/java/io/kestra/plugin/mongodb/Aggregate.java
#	src/main/java/io/kestra/plugin/mongodb/Find.java
#	src/main/java/io/kestra/plugin/mongodb/MongoDbService.java
Use var rObjectIdFormat in Find and Aggregate and pass it to the fetch and store paths, convert the objectIdFormat descriptions in Find, Aggregate and Trigger to text blocks noting rows[0]._id becomes a map with $oid under EXTENDED_JSON, add an Aggregate test with EXTENDED_JSON, and use IdUtils.create() for the ids in the new Trigger test.

Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
@Varshith-Kali

Copy link
Copy Markdown
Contributor Author

Done, every point from this review is in (head ba35d4a):

  • Merged upstream main (e5ba52f): the conflicts in Find, Aggregate and MongoDbService are resolved. The new map() callers from fix(mongodb): warn when the rows kept in the outputs pass 1 MiB #208 now pass the format through, and the new BINARY case sits next to the OBJECT_ID case, so the binary and UUID output from main is kept alongside the objectIdFormat behavior.
  • Inline nits: Find and Aggregate now use var rObjectIdFormat and pass it down to the fetch, fetchOne and store paths.
  • Descriptions: objectIdFormat in Find, Aggregate and Trigger is now a text block like the store description, each with a line saying rows[0]._id becomes a map with $oid under EXTENDED_JSON.
  • Aggregate test: extendedJsonObjectIdsWrapObjectIds in AggregateTest runs an Aggregate with EXTENDED_JSON and asserts _id comes back as a $oid map.
  • Trigger test: the new triggerWithExtendedJsonObjectIdsWrapsObjectIds test now uses IdUtils.create() for the trigger id and the flow id, with the trigger context ids matching.
  • Screenshot: I could not add a genuine one. This environment has no Docker and no running Kestra instance against MongoDB, so I cannot produce a real screenshot of a Find with store: true followed by Load keeping the ObjectId, and I did not mock one up. The round trip itself is covered by findStoreThenLoadKeepsObjectIds, which asserts the copy keeps every ObjectId.

One honest caveat: the MongoDB-backed suite could not run here (no Docker for Testcontainers, and the Gradle daemon fails to start in this sandbox), so this push is not verified by a local test run yet. CI is the check for that.

@Malaydewangan09

Copy link
Copy Markdown
Member

The tests from main still called map() without the format, so the test build failed. Fixed in 480e6d4 by passing HEX, the suite is green here. Could you update the PR description (hex stays the default, objectIdFormat: EXTENDED_JSON gives the $oid round trip) and add a screenshot of a Find with store: true then Load keeping the ObjectId?

I pushed these tweaks.

@Malaydewangan09
Malaydewangan09 merged commit f4f3101 into kestra-io:main Nov 3, 2026
3 checks passed
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Find with store: true then Load silently converts every ObjectId to a string, so references stop matching

2 participants