def __setitem__(self, key, value):
        """
        Sets the new value. First it validates the input.
        """
        # Check if the variable is defined.
        try:
            config_variable = config.get_config_variables()[key]
        except KeyError:
            raise ConfigNotFound(_('The config variable %s was not found.') % key)

        # Validate datatype and run validators.
        expected_type = INPUT_TYPE_MAPPING[config_variable.input_type]

        # Try to convert value into the expected datatype
        try:
            value = expected_type(value)
        except __HOLE__:
            raise ConfigError(_('Wrong datatype. Expected %(expected_type)s, got %(got_type)s.') % {
                'expected_type': expected_type, 'got_type': type(value)})
        if config_variable.input_type == 'choice' and value not in map(lambda choice: choice['value'], config_variable.choices):
            raise ConfigError(_('Invalid input. Choice does not match.'))
        for validator in config_variable.validators:
            try:
                validator(value)
            except DjangoValidationError as e:
                raise ConfigError(e.messages[0])

        # Save the new value to the database.
        config_store, created = ConfigStore.objects.get_or_create(key=key, defaults={'value': value})
        if not created:
            config_store.value = value
            config_store.save()

        # Update cache.
        if hasattr(self, '_cache'):
            self._cache[key] = value

        # Call on_change callback.
        if config_variable.on_change:
            config_variable.on_change()
dataset/ETHPy150Open OpenSlides/OpenSlides/openslides/core/config.py/ConfigHandler.__setitem__