<commit_before>from xblock.runtime import KeyValueStore, InvalidScopeError


class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request, descriptor_model_data):
        self._descriptor_model_data = descriptor_model_data
        self._session = request.session

    def get(self, key):
        try:
            return self._descriptor_model_data[key.field_name]
        except (KeyError, InvalidScopeError):
            return self._session[tuple(key)]

    def set(self, key, value):
        try:
            self._descriptor_model_data[key.field_name] = value
        except (KeyError, InvalidScopeError):
            self._session[tuple(key)] = value

    def delete(self, key):
        try:
            del self._descriptor_model_data[key.field_name]
        except (KeyError, InvalidScopeError):
            del self._session[tuple(key)]

    def has(self, key):
        return key in self._descriptor_model_data or key in self._session<commit_msg>Fix SessionKeyValueStore.has to use the correct indexing value when looking up data<commit_after>from xblock.runtime import KeyValueStore, InvalidScopeError


class SessionKeyValueStore(KeyValueStore):
    def __init__(self, request, descriptor_model_data):
        self._descriptor_model_data = descriptor_model_data
        self._session = request.session

    def get(self, key):
        try:
            return self._descriptor_model_data[key.field_name]
        except (KeyError, InvalidScopeError):
            return self._session[tuple(key)]

    def set(self, key, value):
        try:
            self._descriptor_model_data[key.field_name] = value
        except (KeyError, InvalidScopeError):
            self._session[tuple(key)] = value

    def delete(self, key):
        try:
            del self._descriptor_model_data[key.field_name]
        except (KeyError, InvalidScopeError):
            del self._session[tuple(key)]

    def has(self, key):
        return key.field_name in self._descriptor_model_data or tuple(key) in self._session
{'fraction_non_alphanumeric': 0.08201581027667984, 'fraction_numerical': 0.0, 'mean_word_length': 2.9705882352941178, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5995808', 'n_tokens_mistral': 555, 'n_tokens_neox': 543, 'n_words': 130}