Repository: getsentry/sentry

Issue:
Discarded invalid value for parameter 'breadcrumbs'
With Sentry 8.4 and RavenJS 3.0.4, why might the breadcrumbs parameter be discarded?

Scenario:
- I land on a page which tries to call a nonexistant function (fooltip)
- RavenJS's window.onerror handler fires and sends two POSTs to Sentry for that error.  The first has no breadcrumbs, but the second one does (predictably).  I'm not sure why it sends two; there is only one error.  
- I then run `try { throw new Error('test error') } catch (e) { Raven.captureException(e); }`

There are now three error events in Sentry:
1. the first window.onerror event: appears normally
2. the second window.onerror event: breadcrumbs discarded
3. the manually-captured error: breadcrumbs discarded

The JSON below is from the manually-captured `Error('test error')`.

Here's the JSON from the POST body (RavenJS->Sentry):

```
{
    "breadcrumbs": {
        "values": [
            {
                "category": "sentry",
                "event_id": "44d29216b5bd491cacae24612747f506",
                "message": "TypeError: $(...).fooltip is not a function",
                "timestamp": 1462979789.345
            },
            {
                "category": "sentry",
                "event_id": "b17440c6072547cf8fed1e8979afec03",
                "message": "TypeError: $(...).fooltip is not a function",
                "timestamp": 1462979789.348
            },
            {
                "category": "console",
                "level": "error",
                "message": "TypeError: $(...).fooltip is not a function",
                "timestamp": 1462979789.349
            },
            {
                "category": "xhr",
                "data": {
                    "method": "GET",
                    "status_code": 200,
                    "url": "https://dev-mclayton.usersys.redhat.com/api/banners"
                },
                "timestamp": 1462979790.243,
                "type": "http"
            }
        ]
    },
    "culprit": "<anonymous>",
    "event_id": "1f85892bd3464c2fbea01050f3cc5b80",
    "exception": {
        "values": [
            {
                "stacktrace": {
                    "frames": [
                        {
                            "colno": 14,
                            "filename": "<anonymous>",
                            "function": "Object.InjectedScript.evaluate",
                            "in_app": true,
                            "lineno": 118
                        },
                        {
                            "colno": 25,
                            "filename": "<anonymous>",
                            "function": "Object.InjectedScript._evaluateAndWrap",
                            "in_app": true,
                            "lineno": 137
                        },
                        {
                            "colno": 167,
                            "filename": "<anonymous>",
                            "function": "Object.InjectedScript._evaluateOn",
                            "in_app": true,
                            "lineno": 145
                        }
                    ]
                },
                "type": "Error",
                "value": "test error"
            }
        ]
    },
    "extra": {
        "session:duration": 291512
    },
    "logger": "javascript",
    "message": "Error: test error",
    "platform": "javascript",
    "project": "3",
    "request": {
        "headers": {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36"
        },
        "url": "https://dev-mclayton.usersys.redhat.com/"
    },
    "user": {
        "internal": false,
        "lang": "en",
        "login": ""
    }
}
```

And here's the JSON from the Sentry UI (ie, the JSON (2.0KB) link on the event page):

```
{
    "id": "1f85892bd3464c2fbea01050f3cc5b80",
    "project": 3,
    "release": null,
    "platform": "javascript",
    "culprit": "<anonymous> in Object.InjectedScript._evaluateOn",
    "message": "Error: test error",
    "datetime": "2016-05-11T15:21:18.000000Z",
    "time_spent": null,
    "tags": [
        [
            "level",
            "error"
        ],
        [
            "logger",
            "javascript"
        ],
        [
            "browser",
            "Chrome 50.0"
        ],
        [
            "device",
            "Other"
        ],
        [
            "os",
            "Linux"
        ],
        [
            "url",
            "https://dev-mclayton.usersys.redhat.com/"
        ],
        [
            "sentry:user",
            "ip:10.13.49.57"
        ]
    ],
    "errors": [
        {
            "type": "invalid_data",
            "name": "breadcrumbs",
            "value": {
                "values": [
                    {
                        "category": "sentry",
                        "timestamp": 1462979789.345,
                        "message": "TypeError: $(...).fooltip is not a function",
                        "event_id": "44d29216b5bd491cacae24612747f506"
                    },
                    {
                        "category": "sentry",
                        "timestamp": 1462979789.348,
                        "message": "TypeError: $(...).fooltip is not a function",
                        "event_id": "b17440c6072547cf8fed1e8979afec03"
                    },
                    {
                        "category": "console",
                        "timestamp": 1462979789.349,
                        "message": "TypeError: $(...).fooltip is not a function",
                        "level": "error"
                    },
                    {
                        "category": "xhr",
                        "timestamp": 1462979790.243,
                        "type": "http",
                        "data": {
                            "url": "https://dev-mclayton.usersys.redhat.com/api/banners",
                            "status_code": 200,
                            "method": "GET"
                        }
                    }
                ]
            }
        },
        {
            "url": "<anonymous>",
            "type": "js_no_source"
        },
        {
            "url": "<anonymous>",
            "type": "js_no_source"
        },
        {
            "url": "<anonymous>",
            "type": "js_no_source"
        }
    ],
    "extra": {
        "session:duration": 291512
    },
    "fingerprint": [
        "{{ default }}"
    ],
    "received": 1462980078,
    "sdk": {
        "version": "3.0.4",
        "name": "raven-js"
    },
    "sentry.interfaces.Exception": {
        "exc_omitted": null,
        "values": [
            {
                "stacktrace": {
                    "has_system_frames": false,
                    "frames": [
                        {
                            "function": "Object.InjectedScript.evaluate",
                            "abs_path": "<anonymous>",
                            "in_app": false,
                            "lineno": 118,
                            "colno": 14,
                            "filename": "<anonymous>"
                        },
                        {
                            "function": "Object.InjectedScript._evaluateAndWrap",
                            "abs_path": "<anonymous>",
                            "in_app": false,
                            "lineno": 137,
                            "colno": 25,
                            "filename": "<anonymous>"
                        },
                        {
                            "function": "Object.InjectedScript._evaluateOn",
                            "abs_path": "<anonymous>",
                            "in_app": false,
                            "lineno": 145,
                            "colno": 167,
                            "filename": "<anonymous>"
                        }
                    ],
                    "frames_omitted": null
                },
                "type": "Error",
                "value": "test error",
                "module": null
            }
        ]
    },
    "sentry.interfaces.Http": {
        "url": "https://dev-mclayton.usersys.redhat.com/",
        "headers": [
            [
                "User-Agent",
                "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36"
            ]
        ]
    },
    "sentry.interfaces.User": {
        "data": {
            "lang": "en",
            "login": "",
            "internal": false
        },
        "ip_address": "10.13.49.57"
    },
    "type": "error",
    "version": "7"
}
```

Thanks in advance!



Discussion:

Resolving patch:
diff --git a/src/sentry/coreapi.py b/src/sentry/coreapi.py
--- a/src/sentry/coreapi.py
+++ b/src/sentry/coreapi.py
@@ -349,6 +349,12 @@ def validate_data(self, project, data):
 
         data['errors'] = []
 
+        # Ignore any breadcrumbs data sent in older versions
+        # of sentry server to be more backwards compatible without
+        # yelling on every recorded event
+        data.pop('breadcrumbs', None)
+        data.pop('sentry.interfaces.Breadcrumbs', None)
+
         if not data.get('message'):
             data['message'] = '<no message value>'
         elif not isinstance(data['message'], six.string_types):


Test patch: