Repository: liberapay/liberapay.com

Issue:
Take-over failure during account migration
https://sentry.io/share/issue/8bcc0a6744cf432884595c98ec10a120/


Discussion:
So, why I am not being added to this "participants" table from Gratipay?

Resolving patch:
diff --git a/liberapay/wireup.py b/liberapay/wireup.py
--- a/liberapay/wireup.py
+++ b/liberapay/wireup.py
@@ -381,7 +381,7 @@ def tell_sentry(exception, state, allow_reraise=True):
             # Reraise if allowed
             if env.sentry_reraise and allow_reraise:
                 raise
-            return
+            return {'sentry_ident': None}
 
         user = state.get('user')
         extra = {}
@@ -404,7 +404,7 @@ def tell_sentry(exception, state, allow_reraise=True):
         result = sentry.captureException(tags=tags, extra=extra)
 
         # Put the Sentry id in the state for logging, etc
-        state['sentry_ident'] = sentry.get_ident(result)
+        return {'sentry_ident': sentry.get_ident(result)}
 
     CustomUndefined._tell_sentry = staticmethod(tell_sentry)
 


Test patch:
diff --git a/tests/py/test_migrate.py b/tests/py/test_migrate.py
new file mode 100644
--- /dev/null
+++ b/tests/py/test_migrate.py
@@ -0,0 +1,68 @@
+from __future__ import division, print_function, unicode_literals
+
+from os.path import abspath
+
+from aspen import resources
+from mock import MagicMock, patch
+
+from liberapay.constants import EPOCH
+from liberapay.models.participant import Participant
+from liberapay.testing import Harness
+from liberapay.utils import NS
+
+
+initial_data = dict(
+    id='-1',
+    username='alice',
+    email_address='alice@example.net',
+    session_token='foobar',
+)
+
+gratipay_response = NS(
+    json=lambda: dict(
+        initial_data,
+        anonymous_giving=False,
+        avatar_url='https://example.net/alice/avatar',
+        email_lang='en',
+        is_searchable=True,
+        email_addresses=[
+            dict(
+                address=initial_data['email_address'],
+                verified=True,
+                verification_start=EPOCH,
+                verification_end=EPOCH,
+            ),
+        ],
+        payment_instructions=[dict()],  # TODO
+        elsewhere=[dict()],  # TODO
+        statements=[dict()],  # TODO
+        teams=[dict()],  # TODO
+    ),
+    status_code=200,
+)
+
+class TestMigrate(Harness):
+
+    def test_migrate(self):
+        # Step 1
+        r = self.client.POST('/migrate', initial_data)
+        assert r.code == 200
+        assert "Welcome, alice!" in r.text, r.text
+        # Step 2
+        cache_entry = resources.__cache__[abspath('www/migrate.spt')]
+        simplate_context = cache_entry.resource.pages[0]
+        requests = MagicMock()
+        requests.post.return_value = gratipay_response
+        with patch.dict(simplate_context, {'requests': requests}):
+            r = self.client.PxST('/migrate?step=2', initial_data, sentry_reraise=False)
+            assert r.code == 302
+            assert r.headers[b'Location'] == b'?step=3'
+        # Step 3
+        alice = Participant.from_id(1)
+        r = self.client.GET('/migrate?step=3', auth_as=alice)
+        assert r.code == 200
+
+    def test_migrate_without_initial_data(self):
+        r = self.client.POST('/migrate', {k: '' for k in initial_data})
+        assert r.code == 200
+        assert "Oops, you need to go back to Gratipay " in r.text, r.text