def ensure_one_subscription():
    """
    Fixes issues caused by upstream failures
    that lead to users having multiple active subscriptions
    Runs daily
    """
    cursor = connection.cursor()
    cursor.execute("UPDATE subscription_subscription SET active = False \
                    WHERE id NOT IN \
                   (SELECT MAX(id) as id FROM \
                    subscription_subscription GROUP BY to_addr)")
    affected = cursor.rowcount
    vumi_fire_metric.delay(
        metric="subscription.duplicates", value=affected, agg="last")
    return affected
def ensure_one_subscription ( ) : cursor = connection . cursor ( ) cursor . execute ( "UPDATE subscription_subscription SET active = False \
                    WHERE id NOT IN \
                   (SELECT MAX(id) as id FROM \
                    subscription_subscription GROUP BY to_addr)" ) affected = cursor . rowcount vumi_fire_metric . delay ( metric = "subscription.duplicates" , value = affected , agg = "last" ) return affected
Fixes issues caused by upstream failures
    that lead to users having multiple active subscriptions
    Runs daily