<commit_before>from django.core.exceptions import ObjectDoesNotExist
from hyquest.models import TaskCode
from hyquest.verifiers.common import getUserAction

def matchingCodeTasks(user, code):
    task = getTaskForCode(code)
    if task is None:
        return ([], [])
    action = getUserAction(user, task)
    if action is None:
        burnCode(code)
        return ([], [task,])
    if action.complete:
        return ([], [])
    burnCode(code)
    return ([task,],[])

def getTaskForCode(code):
    try:
        tcode = TaskCode.objects.get(code=code)
        if tcode.uses_remaining<1:
            return None
        task = tcode.task
        if task.quest.quest_set.active:
            return task
        return None
    except ObjectDoesNotExist:
        return None

def burnCode(code):
    try:
        taskcode = TaskCode.objects.get(code=code)
        taskcode.uses_remaining -= 1
        taskcode.save()
    except ObjectDoesNotExist:
        pass
    return<commit_msg>Burn codes atomically, so that multi-use cannot occur<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django.db.models import F
from hyquest.models import TaskCode
from hyquest.verifiers.common import getUserAction

def matchingCodeTasks(user, code):
    task = getTaskForCode(code)
    if task is None:
        return ([], [])
    action = getUserAction(user, task)
    if action is None:
        burnCode(code)
        return ([], [task,])
    if action.complete:
        return ([], [])
    burnCode(code)
    return ([task,],[])

def getTaskForCode(code):
    try:
        tcode = TaskCode.objects.get(code=code)
        if tcode.uses_remaining<1:
            return None
        task = tcode.task
        if task.quest.quest_set.active:
            return task
        return None
    except ObjectDoesNotExist:
        return None

def burnCode(code):
    try:
        taskcode = TaskCode.objects.get(code=code)
        taskcode.uses_remaining = F('uses_remaining')-1
        taskcode.save()
    except ObjectDoesNotExist:
        pass
    return
{'fraction_non_alphanumeric': 0.0950533462657614, 'fraction_numerical': 0.0019398642095053346, 'mean_word_length': 2.5144804088586032, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1429002', 'n_tokens_mistral': 619, 'n_tokens_neox': 614, 'n_words': 153}