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. #15656

Closed
restfulhead opened this issue Jun 10, 2021 · 2 comments
Closed
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Search

Comments

@restfulhead
Copy link

restfulhead commented Jun 10, 2021

  • Package Name: @azure/search-documents
  • Package Version: 11.0.3
  • Operating system: OSX
  • [x ] nodejs
    • version: 12 and 14
  • [x ] typescript
    • version: 4.2

Describe the bug
When your search document has an array field and you try to index two documents with the same object inside the array, indexing fails with the following error:

Cannot map a recusive structure. Error: Cannot map a recusive structure. at walk (D:\home\site\wwwroot\node_modules\@azure\search-documents\dist\index.js:1862:23) at serialize (D:\home\site\wwwroot\node_modules\@azure\search-documents\dist\index.js:1839:12) at SearchClient$1.<anonymous> (D:\home\site\wwwroot\node_modules\@azure\search-documents\dist\index.js:3400:77) at Generator.next (<anonymous>) at D:\home\site\wwwroot\node_modules\@azure\search-documents\node_modules\tslib\tslib.js:114:75 at new Promise (<anonymous>) at Object.__awaiter (D:\home\site\wwwroot\node_modules\@azure\search-documents\node_modules\tslib\tslib.js:110:16) at SearchClient$1.indexDocuments (D:\home\site\wwwroot\node_modules\@azure\search-documents\dist\index.js:3397:22) at SearchClient$1.<anonymous> (D:\home\site\wwwroot\node_modules\@azure\search-documents\dist\index.js:3429:35) at Generator.next (<anonymous>) {}
Error

It seems to be caused by the serializer which does not seem to allow using the same object more than once: https://github.com/Azure/azure-sdk-for-js/blob/%40azure/search-documents_11.0.3/sdk/search/search-documents/src/serialization.ts#L37

When you pass multiple documents to SearchClient.uploadDocuments it seems that it calls serialize on the whole array. Then if document 1 and document 2 share the same child object, it fails. A workaround could be to iterate over the documents and call serialize once per document and not on the array. It would still fail if one document references the same child, but that probably doesn't happen too often.

To Reproduce

const child = { hello: 'world' }
const documents = [
        { id: '1', children: [child] },
        { id: '2', children: [child] },
]

// search example which throws exception
SearchClient.uploadDocuments(documents)

// root cause, serialize throws exception 
serialize(documents)

// workaround
const documents = [
        { id: '1', children: [{ ...child }] },
        { id: '2', children: [{ ...child }] },
      ]

Expected behavior
I should be able to index multiple document that reference the same child objects. To get around it I have to copy the values over to create unique child objects.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 10, 2021
@ramya-rao-a ramya-rao-a added Client This issue points to a problem in the data-plane of the library. Search labels Jun 10, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 10, 2021
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jun 10, 2021
@mattnield
Copy link

I'm getting the same issue on a project that I'm working on too. For me, I wasn't aware that I did have child objects. If it helps, here is the dataset that causes me issue:

[
  {
    "id": "2dfa8248-2e67-4686-b157-403ed25f3cd8|a78327f6-cee2-4338-978e-49451b9e5977",
    "display_name": "Artist XX - Street Album Release (test) ",
    "search_data": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — inclu  ding tastings and restaurant tours — spread out across the entire of October.</p>Charing Cross Road",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — including tastings and restaurant tours — spread out across the entire of October.</p>",
    "start_date": "2021-10-12T18:00:00.000Z",
    "end_date": "2021-10-12T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5110704,
        -0.1284451198
      ]
    },
    "location_codename": "charring_cross_road",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "2dfa8248-2e67-4686-b157-403ed25f3cd8|a1d36f1c-7c12-45ef-adc9-7bdf2e173ce5",
    "display_name": "Artist XX - Street Album Release (test) ",
    "search_data": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — including tastings and restaurant tours — spread out across the entire of October.</p>St. Pauls",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — including tastings and restaurant tours — spread out across the entire of October.</p>",
    "start_date": "2021-10-19T18:00:00.000Z",
    "end_date": "2021-10-19T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5139649,
        -0.095404221
      ]
    },
    "location_codename": "st__pauls",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "2dfa8248-2e67-4686-b157-403ed25f3cd8|2b7b76f0-0060-4921-92d9-22f99ecb8462",
    "display_name": "Artist XX - Street Album Release (test) ",
    "search_data": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — including tastings and restaurant tours — spread out across the entire of October.</p>Woking",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>The&nbsp;London Restaurant Festival&nbsp;has revealed the line-up for this year’s edition, which marks the 13th year the event has been held across the city.</p>\n<p>The festival, which hopes to celebrate the best of the capital’s cooking, this year boasts more than 50 happenings — including tastings and restaurant tours — spread out across the entire of October.</p>",
    "start_date": "2021-10-22T18:00:00.000Z",
    "end_date": "2021-10-22T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.3199013,
        -0.5596662
      ]
    },
    "location_codename": "woking",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "49560bee-2790-43d0-8e48-f36877ed8db2|a78327f6-cee2-4338-978e-49451b9e5977",
    "display_name": "Artist Street Party (test) ",
    "search_data": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>Charing Cross Road",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>",
    "start_date": "2021-10-12T18:00:00.000Z",
    "end_date": "2021-10-12T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5110704,
        -0.1284451198
      ]
    },
    "location_codename": "charring_cross_road",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "49560bee-2790-43d0-8e48-f36877ed8db2|a1d36f1c-7c12-45ef-adc9-7bdf2e173ce5",
    "display_name": "Artist Street Party (test) ",
    "search_data": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>St. Pauls",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>",
    "start_date": "2021-10-19T18:00:00.000Z",
    "end_date": "2021-10-19T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5139649,
        -0.095404221
      ]
    },
    "location_codename": "st__pauls",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "49560bee-2790-43d0-8e48-f36877ed8db2|2b7b76f0-0060-4921-92d9-22f99ecb8462",
    "display_name": "Artist Street Party (test) ",
    "search_data": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>Woking",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>Street PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet PartyStreet Party</p>",
    "start_date": "2021-10-22T18:00:00.000Z",
    "end_date": "2021-10-22T21:00:00.000Z",
    "price": 0,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.3199013,
        -0.5596662
      ]
    },
    "location_codename": "woking",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "9f2bd3e1-63ee-4c51-a327-2207427adfe4|a78327f6-cee2-4338-978e-49451b9e5977",
    "display_name": "Test Event Title",
    "search_data": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>Charing Cross Road",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>",
    "start_date": "2021-10-12T18:00:00.000Z",
    "end_date": "2021-10-12T21:00:00.000Z",
    "price": 5,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5110704,
        -0.1284451198
      ]
    },
    "location_codename": "charring_cross_road",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "9f2bd3e1-63ee-4c51-a327-2207427adfe4|a1d36f1c-7c12-45ef-adc9-7bdf2e173ce5",
    "display_name": "Test Event Title",
    "search_data": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>St. Pauls",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>",
    "start_date": "2021-10-19T18:00:00.000Z",
    "end_date": "2021-10-19T21:00:00.000Z",
    "price": 5,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.5139649,
        -0.095404221
      ]
    },
    "location_codename": "st__pauls",
    "language": "default",
    "collection": "branding"
  },
  {
    "id": "9f2bd3e1-63ee-4c51-a327-2207427adfe4|2b7b76f0-0060-4921-92d9-22f99ecb8462",
    "display_name": "Test Event Title",
    "search_data": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>Woking",
    "image_url": "",
    "item_codename": "super-event",
    "description": "<p>This is the test event description. Aenean <em>fringilla</em> lacinia massa, vel mattis tellus <em>sollicitudin</em> nec. Donec congue leo ac nunc condimentum venenatis. Proin cursus lectus et feugiat tristique.</p>",
    "start_date": "2021-10-22T18:00:00.000Z",
    "end_date": "2021-10-22T21:00:00.000Z",
    "price": 5,
    "object_type": "event",
    "location_coordinates": {
      "type": "Point",
      "coordinates": [
        51.3199013,
        -0.5596662
      ]
    },
    "location_codename": "woking",
    "language": "default",
    "collection": "branding"
  }
]

@sarangan12
Copy link
Contributor

Code fix merged with PR #18542. Will be released on 9th.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Search
Projects
None yet
Development

No branches or pull requests

4 participants