From 5f2b0b0ecc1d5a6c09262724b7da27d39b60ae21 Mon Sep 17 00:00:00 2001 From: Zbynek Winkler Date: Sun, 12 Jan 2014 18:48:40 +0100 Subject: [PATCH 1/3] Failing test for running take_over twice. When user manages to run take_over twice with the same arguments, tak_over creates an orphan. --- tests/test_participant.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_participant.py b/tests/test_participant.py index 040395125f..b2d3fe3ea4 100644 --- a/tests/test_participant.py +++ b/tests/test_participant.py @@ -167,6 +167,14 @@ def test_do_not_take_over_zero_tips_receiving(self): assert 2 == ntips self.db.self_check() + def test_idempotent(self): + alice = TwitterAccount(self.db, 1, dict(screen_name='alice')) + bob = GitHubAccount(self.db, 2, dict(screen_name='bob')) + alice_participant = alice.opt_in('alice')[0].participant + alice_participant.take_over(bob, have_confirmation=True) + alice_participant.take_over(bob, have_confirmation=True) + self.db.self_check() + class TestParticipant(Harness): def setUp(self): From 981bd902fd23534cc077859ee114cb52d95061e8 Mon Sep 17 00:00:00 2001 From: Zbynek Winkler Date: Sun, 12 Jan 2014 19:36:57 +0100 Subject: [PATCH 2/3] Make take_over idempotent (fixes #617). --- gittip/models/__init__.py | 24 +----------------------- gittip/models/_mixin_elsewhere.py | 4 ++++ 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/gittip/models/__init__.py b/gittip/models/__init__.py index 31a241284c..e2714abc28 100644 --- a/gittip/models/__init__.py +++ b/gittip/models/__init__.py @@ -108,29 +108,7 @@ def _check_orphans(self): where not exists (select * from elsewhere where elsewhere.participant=username) and not exists (select * from absorptions where archived_as=username) """) - known = set(( - "4c46cc22afdd", - "82b0d81fe9e8", - "6b6527ac6c02", - "cbde8c31c11c", - "bcfc65158eaf", - "31d54a0c19ae", - "afbddadaac3c", - "a78c4e42bb93", - "42eb93b3ab89", - "b1bc5e47fe8e", - "3ac515cc8da6", - "14a79340c40d", - "14d60c6884e7", - "0c783dee50ed", - "e2020536ef6d", - "60a5099d49c7", - "64f4f959b322", - "0bdf90d51786", - "880ac6873f7f" - )) - real = set(orphans) - known - assert len(real) == 0, "missing elsewheres: {}".format(list(real)) + assert len(orphans) == 0, "missing elsewheres: {}".format(list(orphans)) def _check_orphans_no_tips(self): """ diff --git a/gittip/models/_mixin_elsewhere.py b/gittip/models/_mixin_elsewhere.py index a2d66109d3..51c19d6aa5 100644 --- a/gittip/models/_mixin_elsewhere.py +++ b/gittip/models/_mixin_elsewhere.py @@ -269,6 +269,10 @@ def take_over(self, account_elsewhere, have_confirmation=False): other_username = rec.participant + if self.username == other_username: + # this is a no op - trying to take over itself + return + # Make sure we have user confirmation if needed. # ============================================== From 43869ff43cc1715c648eb1d9e9a2f77bd57d6326 Mon Sep 17 00:00:00 2001 From: Zbynek Winkler Date: Mon, 13 Jan 2014 20:42:58 +0100 Subject: [PATCH 3/3] Update branch.sql to delete the offending users. --- branch.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 branch.sql diff --git a/branch.sql b/branch.sql new file mode 100644 index 0000000000..9bcf155abc --- /dev/null +++ b/branch.sql @@ -0,0 +1,20 @@ +DELETE FROM participants WHERE username = ANY( ARRAY[ + '4c46cc22afdd', + '82b0d81fe9e8', + '6b6527ac6c02', + 'cbde8c31c11c', + 'bcfc65158eaf', + '31d54a0c19ae', + 'afbddadaac3c', + 'a78c4e42bb93', + '42eb93b3ab89', + 'b1bc5e47fe8e', + '3ac515cc8da6', + '14a79340c40d', + '14d60c6884e7', + '0c783dee50ed', + 'e2020536ef6d', + '60a5099d49c7', + '64f4f959b322', + '0bdf90d51786', + '880ac6873f7f']);