<commit_before>from req import Service
from service.base import BaseService


class Clarification(BaseService):
    def get_clarification_list(self):
        res = yield self.db.execute("SELECT * FROM clarifications ORDER BY id ASC")
        res = res.fetchall()
        return (None, res)

    def get_clarification(self, data={}):
        required_args = [{
            'name': '+id',
            'type': int,
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        res = yield self.db.execute("SELECT * FROM clarifications WHERE id=%s", (data['id'],))
        res = res.fetchone()
        return (None, res)

    def post_clarification(self, data={}):
        required_args = [{
            'name': '+user_id',
            'type': int,
        }, {
            'name': '+problem_id',
            'type': int,
        }, {
            'name': '+question',
            'type': str,
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        sql, param = self.gen_insert_sql('clarifications', data)
        res = yield self.db.execute(sql, param)
        res = res.fetchone()
        return (None, res)

    def put_clarification(self, data={}):
        required_args = [{
            'name': '+id',
            'type': int,
        }, {
            'name': '+reply',
            'type': str,
        }, {
            'name': '+reply_type',
            'type': int,
            'range': (0, 1)
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        id = data.pop('id')
        sql, param = self.gen_update_sql('clarifications', data)
        res = yield self.db.execute(sql + ' WHERE id = %s', param + (id,))
        return (None, None)
<commit_msg>fixed clarification reply can be empty string<commit_after>from req import Service
from service.base import BaseService


class Clarification(BaseService):
    def get_clarification_list(self):
        res = yield self.db.execute("SELECT * FROM clarifications ORDER BY id ASC")
        res = res.fetchall()
        return (None, res)

    def get_clarification(self, data={}):
        required_args = [{
            'name': '+id',
            'type': int,
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        res = yield self.db.execute("SELECT * FROM clarifications WHERE id=%s", (data['id'],))
        res = res.fetchone()
        return (None, res)

    def post_clarification(self, data={}):
        required_args = [{
            'name': '+user_id',
            'type': int,
        }, {
            'name': '+problem_id',
            'type': int,
        }, {
            'name': '+question',
            'type': str,
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        sql, param = self.gen_insert_sql('clarifications', data)
        res = yield self.db.execute(sql, param)
        res = res.fetchone()
        return (None, res)

    def put_clarification(self, data={}):
        required_args = [{
            'name': '+id',
            'type': int,
        }, {
            'name': '+reply',
            'type': str,
            'non_empty': True,
        }, {
            'name': '+reply_type',
            'type': int,
            'range': (0, 1)
        }]
        err = self.form_validation(data, required_args)
        if err: return (err, None)
        id = data.pop('id')
        sql, param = self.gen_update_sql('clarifications', data)
        res = yield self.db.execute(sql + ' WHERE id = %s', param + (id,))
        return (None, None)

{'fraction_non_alphanumeric': 0.14289595218690573, 'fraction_numerical': 0.0010866612333604998, 'mean_word_length': 1.8698363211223694, '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': '3808096', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1083, 'n_words': 280}