Skip to content

[BUG] CSV reports will fail when a date field is an empty list #262

@zhongnansu

Description

@zhongnansu

Describe the bug

  • Error message
{"statusCode":500,"error":"Internal Server Error","message":"Cannot read property '0' of undefined"}

For example

  • mapping:
{
  "test" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "dates" : {
          "type" : "date"
        },
        "message" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}
  • sample data
 {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2021-12-17T14:03:21",
          "message" : "first",
          "dates" : [ ]
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "@timestamp" : "2021-12-17T14:03:21",
          "message" : "first",
          "dates" : [
            "2021-12-17T14:04:55",
            "2021-12-17T14:03:55"
          ]
        }
      },
  • in Discover
    image

Root cause

This code is causing the issue.
if (data._source[dateType]) will pass for an empty list, and failed the following logic. Need to put more restriction on this check. Also, for logic of parsing the only the first elements doesn't seem right. It should parse everything.

https://github.com/opensearch-project/dashboards-reports/blob/main/dashboards-reports/server/routes/utils/dataReportHelpers.ts#L117-L127

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions