Skip to content

fix(joins): allow null optional nested references in object arrays on update#2852

Open
tharropoulos wants to merge 2 commits intotypesense:v31from
tharropoulos:null-patchy-join
Open

fix(joins): allow null optional nested references in object arrays on update#2852
tharropoulos wants to merge 2 commits intotypesense:v31from
tharropoulos:null-patchy-join

Conversation

@tharropoulos
Copy link
Copy Markdown
Contributor

Change Summary

  • allow optional nested reference fields in object arrays to skip null values during update and async reference handling
  • accept signed and unsigned json integers within the uint32 range for nested reference
    helper arrays
  • add tests for nested reference updates, code-based references and mixed null/unresolved async cases

PR Checklist

… update

- skip null child reference values in object-array reference handling when the field is optional
- add a regression test for patch-style updates on nested optional references
- allow internal nested reference helper arrays to validate both signed
and unsigned json integers within the uint32 range
- add tests for optional nested refs on update and async
null/unresolved mixed object arrays
@kishorenc
Copy link
Copy Markdown
Member

@happy-san Please review.

Comment thread src/validator.cpp
#include "validator.h"
#include "field.h"

namespace {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tharropoulos Is there a reason for having namespace here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair point. The unnamed namespace is only there to keep is_valid_uint32_json_integer file specific. Should I just change it to a static for consistency?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll let @kishorenc take that call.

ASSERT_EQ(0, doc["relatedassetsdata"][0].count("childobjectid"));
}

TEST_F(CollectionJoinTest, UpdateOptionalNestedReferenceInObjectArrayViaPatchPathOnCodeField) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test passes even without the changes in this PR. Could you check if we're testing the change correctly?

Copy link
Copy Markdown
Contributor Author

@tharropoulos tharropoulos Apr 1, 2026

Choose a reason for hiding this comment

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

I tried tightening it a few ways to mirror the failing cases more closely, like switching to the single-document UPDATE path, changing null -> valid code reference, and adding multiple object-array slots so the helper field had to record a non-zero object index, but it still passed without the fix.

At this point it seems this code-field variant is not targeting the broken path the PR fixes, while the two tests that do fail without the seem to be the real regressions.

So I agree the current test is not validating the change correctly, and I'd treat it as general coverage rather than evidence for the fix unless you had a specific pre-fix repro in mind for that variant.

EDIT: readability changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I found the reason, could you check if this test hits the else if (optional && object_array[i].at(keys[1]).is_null()) condition at line 278.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay. Let's keep this test as is. The issue was only with the id field reference in an object array then.

@tharropoulos tharropoulos requested a review from happy-san April 1, 2026 09:47
@happy-san
Copy link
Copy Markdown
Contributor

@kishorenc apart from the namespace, the rest seems good to me.

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.

3 participants