@shared_task()
def create_group_notification(message_id, userthread_id):
    # Import here to avoid circular import
    from open_connect.connectmessages.models import Message, UserThread
    message = Message.objects.select_related('thread').get(pk=message_id)
    userthread = UserThread.objects.select_related('user').extra(
        select={
            'subscription_id': 'notifications_subscription.id',
            'subscription_period': 'notifications_subscription.period'
        },
        tables=['notifications_subscription'],
        where=[
            'notifications_subscription.user_id=accounts_user.id',
            'notifications_subscription.group_id=%s'
        ],
        params=[message.thread.group_id]
    ).get(id=userthread_id)

    try:
        notification = Notification.objects.create(
            recipient_id=userthread.user.pk,
            subscription_id=userthread.subscription_id,
            message=message
        )

        if userthread.subscription_period == 'immediate':
            send_immediate_notification.delay(notification.pk)
    except IntegrityError as exception:
        LOGGER.error(
            'Create Group Notification ' + exception.__cause__)
alert when an IAM Role has a policy allowing 'iam:XxxxxXxxx'.
dataset/ETHPy150Open ofa/connect/open_connect/notifications/tasks.py/create_group_notification--crossover with--dataset/ETHPy150Open Netflix/security_monkey/security_monkey/auditors/iam/iam_role.py/IAMRoleAuditor.check_iam_privileges