From 02b7bcf1a4e05b93a04d5367a2dbd6afec2ea58e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 7 Nov 2012 11:14:43 -0500 Subject: [PATCH] populate_db: Make double-unsubscribes not a fatal error. (imported from commit 4dadb28f9c310659ddd780e98da70da55ace7187) --- zephyr/management/commands/populate_db.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index 26e2267c42..9f5306471f 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -464,8 +464,13 @@ def restore_saved_messages(): continue elif old_message["type"] == "subscription_removed": stream_key = (realms[old_message["domain"]].id, old_message["name"]) - subscribers.setdefault(stream_recipients[stream_key].id, - set()).remove(users[old_message["user"]].id) + user_id = users[old_message["user"]].id + subscribers.setdefault(stream_recipients[stream_key].id, set()) + try: + subscribers[stream_recipients[stream_key].id].remove(user_id) + except KeyError: + print "Error unsubscribing %s from %s: not subscribed" % ( + old_message["user"], old_message["name"]) pending_subs[(stream_recipients[stream_key].id, users[old_message["user"]].id)] = False continue