Bulk user import handles Elasticsearch errors differently with multiple users vs one user
Description
When a bulk user import has Elasticsearch errors, there is no indication when there is more than one user (typical use for bulk). If there is only one user, a misleading error message is returned.
Notice that when we create one user with with a string data.attr1 field, we get a misleading error back:
curl -i -H "Authentication: $APIKEY" -H "X-FusionAuth-TenantId: $TENANT" -H "Content-type: application/json" http://localhost:9011/api/user/import -d '{
"users": [
{
"email": "username5@test.com",
"password": "password",
"username": "username5",
"data": {
"attr1": "value5"
}
}
],
"validateDbConstraints": true
}'
HTTP/1.1 400
{"fieldErrors":{},"generalErrors":[{"code":"[ImportRequestFailed]","message":"An error occurred during the import request. This is most likely due to a unique key constraint which would indicate one or more of the users in the import request already exist in FusionAuth. Re-attempt the request with additional validation by using the [validateDbConstraints] property. If you have already enabled the additional validation and you still receive this error, please open a bug report."}]}
Furthermore, if we create a similar single user with the non bulk endpoint, we don't get an error back.
I expect the bulk user import endpoint to handle Elasticsearch errors consistently, whether importing one user or multiple users . An Elasticsearch specific error message would be helpful. It is also surprising that the user create (non-bulk) endpoint does not report Elasticsearch errors.
Bulk user import handles Elasticsearch errors differently with multiple users vs one user
Description
When a bulk user import has Elasticsearch errors, there is no indication when there is more than one user (typical use for bulk). If there is only one user, a misleading error message is returned.
Observed versions
1.49.1
Affects versions
All
Steps to reproduce
We'll use different custom
data
field types to trigger Elasticsearch errors. There's an existing issue acknowledging problems arising from this, https://github.com/FusionAuth/fusionauth-issues/issues/1149.First, we create two users with a numeric
data.attr1
field.Then we create two users with a string
data.attr1
field.Notice that when we create one user with with a string
data.attr1
field, we get a misleading error back:Furthermore, if we create a similar single user with the non bulk endpoint, we don't get an error back.
We can verify that only the first two users are actually indexed in Elasticsearch
Expected behavior
I expect the bulk user import endpoint to handle Elasticsearch errors consistently, whether importing one user or multiple users . An Elasticsearch specific error message would be helpful. It is also surprising that the user create (non-bulk) endpoint does not report Elasticsearch errors.