This if statement is doing a similar thing to the above -- d.get('_deleted', False). Could you not group line 107 under the condition in 113, and even remove the check on 105 and do it on line 113? And I actually think the in check is clearer than declaring a variable.