Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[azure-search] Serialization fails due to Cannot map a recusive structure #18542

Merged
merged 6 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/search/search-documents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- Renamed `SkillNames` property to `ResetSkillsOptions` (with a `SkillNames` property)
- Renamed `ResetDocs` method to `ResetDocuments` in the SDK client.

### Bugs Fixed

- Fixed the issue with the presence of recursive structure while uploading documents. Please refer [#15656](https://github.com/Azure/azure-sdk-for-js/issues/15656) for further details.

### Features Added

- Added properties `currentState` & `statusDetail` to the `IndexerExecutionResult` object.
Expand Down
2 changes: 1 addition & 1 deletion sdk/search/search-documents/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function walk(start: unknown, mapper: (val: any) => any): any {

if (typeof current.value === "object" && current.value !== null) {
if (seenMarker.has(current.value)) {
throw new Error("Cannot map a recusive structure.");
continue;
} else {
seenMarker.set(current.value, true);
}
Expand Down
56 changes: 50 additions & 6 deletions sdk/search/search-documents/test/internal/serialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,31 @@ describe("serialization.serialize", () => {
});

it("circular", () => {
const circluarInput: any = { a: null };
circluarInput.a = circluarInput;
assert.throws(() => serialize(circluarInput));
const circularInput: any = { a: null };
circularInput.a = circularInput;
const result = serialize(circularInput);
assert.deepEqual(circularInput, result);
});

it("recursive 1", () => {
const child = { hello: "world" };
const documents = [
{ id: "1", children: [child] },
{ id: "2", children: [child] }
];
const result = serialize(documents);
assert.deepEqual(documents, result);
});

it("recursive 2", () => {
const child = { hello: Infinity, world: -Infinity, universe: NaN };
const documents = [
{ id: "1", children: [child] },
{ id: "2", children: [child] },
{ id: "3", children: [child] }
];
const result = serialize(documents);
assert.deepEqual(documents, result);
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't this fail because the result shape is {hello: 'INF', world: '-INF', universe: 'NaN'} instead of the number value after serialization?

});

it("NaN", () => {
Expand Down Expand Up @@ -47,9 +69,31 @@ describe("serialization.deserialize", () => {
});

it("circular", () => {
const circluarInput: any = { a: null };
circluarInput.a = circluarInput;
assert.throws(() => deserialize(circluarInput));
const circularInput: any = { a: null };
circularInput.a = circularInput;
const result = deserialize(circularInput);
assert.deepEqual(circularInput, result);
});

it("recursive 1", () => {
const child = { hello: "world" };
const documents = [
{ id: "1", children: [child] },
{ id: "2", children: [child] }
];
const result = deserialize(documents);
assert.deepEqual(documents, result);
});

it("recursive 2", () => {
const child = { hello: "INF", world: "-INF", universe: "NaN" };
const documents = [
{ id: "1", children: [child] },
{ id: "2", children: [child] },
{ id: "3", children: [child] }
];
const result = deserialize(documents);
assert.deepEqual(documents, result);
});

it("NaN", () => {
Expand Down