def _get_datastore_value_for_expression(self, key, value, config_schema_item=None):
        """
        Retrieve datastore value by first resolving the datastore expression and then retrieving
        the value from the datastore.

        :param key: Full path to the config item key (e.g. "token" / "auth.settings.token", etc.)
        """
        from st2common.services.config import deserialize_key_value

        config_schema_item = config_schema_item or {}
        secret = config_schema_item.get("secret", False)
        if secret or "decrypt_kv" in value:
            LOG.audit(
                "User %s is decrypting the value for key %s from the config within pack %s",
                self.user,
                key,
                self.pack_name,
                extra={
                    "user": self.user,
                    "key_name": key,
                    "pack_name": self.pack_name,
                    "operation": "pack_config_value_decrypt",
                },
            )
        try:
            value = render_template_with_system_and_user_context(
                value=value, user=self.user
            )
        except Exception as e:
            # Throw a more user-friendly exception on failed render
            exc_class = type(e)
            original_msg = six.text_type(e)
            msg = (
                'Failed to render dynamic configuration value for key "%s" with value '
                '"%s" for pack "%s" config: %s %s '
                % (key, value, self.pack_name, exc_class, original_msg)
            )
            raise RuntimeError(msg)

        if value:
            # Deserialize the value
            value = deserialize_key_value(value=value, secret=secret)
        else:
            value = None

        return value

        Retrieve datastore value by first resolving the datastore expression and then retrieving
        the value from the datastore.

        :param key: Full path to the config item key (e.g. "token" / "auth.settings.token", etc.)
        
st2common/st2common/util/config_loader.py