Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
[azure-search] Serialization fails due to Cannot map a recusive struc…
Browse files Browse the repository at this point in the history
…ture (Azure#18542)

* Continue on a recursive structure walking

* Update Changelog

* Update sdk/search/search-documents/test/internal/serialization.spec.ts

Co-authored-by: Jeff Fisher <xirzec@xirzec.com>

* Update sdk/search/search-documents/test/internal/serialization.spec.ts

Co-authored-by: Jeff Fisher <xirzec@xirzec.com>

* Fix Typo

Co-authored-by: Jeff Fisher <xirzec@xirzec.com>
  • Loading branch information
sarangan12 and xirzec authored Nov 6, 2021
1 parent bd26837 commit cde8606
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
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);
});

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

0 comments on commit cde8606

Please sign in to comment.