Repository: getsentry/sentry-python

Issue:
Breadcrumbs type error
We're having an issue with v0.3.2 where `popleft` is called on a list type:

```
File "/srv/frontend/project/lib/python3.5/site-packages/sentry_sdk/hub.py" in add_breadcrumb
  209.             scope._breadcrumbs.popleft()

Exception Type: AttributeError at /
Exception Value: 'list' object has no attribute 'popleft'
```

Discussion:

Patch:
diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py
index b161a4d4..a7056c66 100644
--- a/sentry_sdk/hub.py
+++ b/sentry_sdk/hub.py
@@ -205,8 +205,8 @@ class Hub(with_metaclass(HubMeta)):
             scope._breadcrumbs.append(crumb)
         else:
             logger.info("before breadcrumb dropped breadcrumb (%s)", original_crumb)
-        while len(scope._breadcrumbs) >= client.options["max_breadcrumbs"]:
-            scope._breadcrumbs.popleft()
+        while len(scope._breadcrumbs) > client.options["max_breadcrumbs"]:
+            scope._breadcrumbs.pop(0)
 
     def push_scope(self, callback=None):
         """Pushes a new layer on the scope stack. Returns a context manager


Test patch:
diff --git a/tests/test_basics.py b/tests/test_basics.py
index 1744c1ab..f5fac31d 100644
--- a/tests/test_basics.py
+++ b/tests/test_basics.py
@@ -139,3 +139,20 @@ def test_push_scope_null_client(sentry_init, capture_events):
             capture_exception(e)
 
     assert len(events) == 0
+
+
+def test_breadcrumbs_overflow(sentry_init, capture_events):
+    sentry_init(max_breadcrumbs=10)
+
+    for i in range(20):
+        add_breadcrumb(
+            category="auth", message="Authenticated user %s" % i, level="info"
+        )
+
+    events = capture_events()
+
+    capture_exception(ValueError())
+
+    event, = events
+
+    assert len(event["breadcrumbs"]) == 10