Getting this error: ```{ "level": 50, "time": ...
# community-help
m
Getting this error:
Copy code
{
  "level": 50,
  "time": 1727061558607,
  "pid": 34285,
  "hostname": "Zestsystems-MacBook-Pro.local",
  "err": {
    "type": "ImportError",
    "message": "0 documents imported successfully, 1 documents failed during import. Use `error.importResults` from the raised exception to get a detailed error reason for each document.",
    "stack": "ImportError: 0 documents imported successfully, 1 documents failed during import. Use `error.importResults` from the raised exception to get a detailed error reason for each document.\n    at ImportError.TypesenseError [as constructor] (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Errors/TypesenseError.js:23:28)\n    at new ImportError (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Errors/ImportError.js:25:28)\n    at Documents.<anonymous> (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Documents.js:154:39)\n    at step (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Documents.js:48:23)\n    at Object.next (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Documents.js:29:53)\n    at fulfilled (/Users/mikeyim/projects/work/utc/node_modules/typesense/lib/Typesense/Documents.js:20:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
    "name": "ImportError",
    "importResults": [
      {
        "code": 400,
        "document": "{\"id\":\"65OhIDFEa1QQdVqyoiX2n\",\"name\":\"Awesome Duo\",\"imageUrl\":null,\"size\":2,\"battlerId\":\"icXdIXHSZhAsu8XYMRQI0\",\"createdAt\":\"1727054133\",\"updatedAt\":\"1727054133\",\"isDeleted\":false,\"members\":[{\"id\":\"jUHsJXvZc5_iRYS25n5Cn\",\"teamId\":\"65OhIDFEa1QQdVqyoiX2n\",\"position\":\"Leader\",\"inviteStatus\":\"Accepted\",\"userId\":\"ReslWXNd8UDVy4bkmP1h0\",\"dancer\":{\"id\":\"UipZeQKJPjKilUUoimsSA\",\"userId\":\"ReslWXNd8UDVy4bkmP1h0\",\"battlerId\":\"c5dTrKcIc2s-ITfUvzNFg\",\"username\":\"mikeyimfb\",\"imageUrl\":null,\"nationality\":\"KR\",\"createdAt\":\"1727053829\",\"updatedAt\":\"1727054343793\",\"isDeleted\":false}},{\"id\":\"hUEV0wprXe77xiErLpj0J\",\"teamId\":\"65OhIDFEa1QQdVqyoiX2n\",\"position\":\"Member\",\"inviteStatus\":\"Pending\",\"userId\":\"kUW8XapcgRxpt7eyKVHk8\",\"dancer\":{\"id\":\"YgvcGnXGAI7Oce_QGiuwD\",\"userId\":\"kUW8XapcgRxpt7eyKVHk8\",\"battlerId\":\"_SYSdbsTsSo249We4AlRW\",\"username\":\"facebookmike\",\"imageUrl\":null,\"nationality\":null,\"createdAt\":\"1726979136\",\"updatedAt\":\"1726979136\",\"isDeleted\":false}}],\"leaderUsername\":\"mikeyimfb\"}",
        "error": "Field `members.dancer.nationality` must be an array of string.",
        "success": false
      }
    ]
  },
  "msg": "0 documents imported successfully, 1 documents failed during import. Use `error.importResults` from the raised exception to get a detailed error reason for each document."
}
The schema for team:
Copy code
team: {
            name: 'team',
            num_documents: 0,
            enable_nested_fields: true,
            fields: [
                { name: 'name', type: 'string' },
                { name: 'leaderUsername', type: 'string' },
                { name: 'imageUrl', type: 'string', optional: true },
                { name: 'size', type: 'int32' },
                { name: 'members', type: 'object[]' },
            ] as const,
        },
What could be an issue? I thought the issue would be because the value of members.dancer.nationality being null but members.dancer.imageUrl should be null as well 🤔
f
It mainly has to do with how you defined your schema. You specified members as an array of objects, without defining any sub fields for the
members
array, resulting in Typesense using
auto
for whatever type you pass in for the sub fields from then on. When you first pass a nationality for the first imported documents, Typesense expects each subsequent member to include a string nationality (it says it expects a string array because members is an array). You would have to manually define your members schema underneath it accordingly e.g.
Copy code
{ name: "members.nationality", type: "string[]", "optional": true}
Also worth noting that if your first import request did have an undefined nationality, then Typesense would automatically mark it as optional
If that's not the case, then it may have something to do with passing
null
values into the request, and axios not omitting it from the request itself. If that's the case, please ping me so I can take a look into it (and if possible provide a reproducable example for me to check against)
m
@Fanis Tharropoulos I think its axios not omitting null value. I have cleared the collection and still getting the issue. I have axios resolved to "0.26.1" because newer version of axios within typesense-instantsearch-adapter preventing react native to build. There should be a help thread that I made in the past you can reference (i don't have pro) new schema:
Copy code
team: {
            name: 'team',
            num_documents: 0,
            enable_nested_fields: true,
            fields: [
                { name: 'name', type: 'string' },
                { name: 'leaderUsername', type: 'string' },
                { name: 'imageUrl', type: 'string', optional: true },
                { name: 'size', type: 'int32' },
                { name: 'members', type: 'object[]' },
                { name: "members.dancer.imageUrl", type: "string[]", "optional": true},
                { name: "members.dancer.nationality", type: "string[]", "optional": true},
            ] as const,
        },
Pruning null fields from objs fixed the import issue. Removing resolution field from yarn.lock didn't do anything for me to tho. I will create a repro on this.
https://github.com/zestsystem/typesense-repro I verified it working on repro...
@Fanis Tharropoulos Ok got the repro to break with the same error. It happens when I upgrade yarn from v1.22.19 to v4.5.0 🫠
The latest commit on the repro is just me simply upgrading from yarn-classic to yarn-berry in an effort to use the pkg manager version we are using. Right before the upgrade I was able to import documents with null fields successfully.
f
I'll check it out and try to find a fix for it
I still can't get it to error out, it has to do with using the older axios version that you use, but axios itself is bundled with the js lib, so I don't know how to get it to error. If you actually log out the requests, null values are omitted altogether.
m
Ok I discovered the cause of the issue. When I upgrade to yarn-berry the resolution field in package.json starts to work and pins axios to v0.26.1. If I remove the resolution field and yarn install again I get axios v1.7.7 which works fine without breaking. Now the issue is will using the latest version of axios without the resolution field cause my typesense-instantsearch-adapter to break my react native project (this was the fix for the last help thread)
As suspected I ran into the past issue again once I removed my resolution: https://threads.typesense.org/2J3b5eb Instead of resolving it to 0.26.1 on a workspace root level, I just added axios 0.26.1 as a dependency for the mobile app to get around the issue.