don't release lock when update failed
You probably need to run that in a transaction and rollback the transaction in the event an integrity error occurs:

```python
    try:
        with database.atomic():
            if grouping_key_id:
                grouping_key_obj = hook_log.query_grouping_key_by_id(grouping_key_id)
                grouping_key_obj.service_name = service_name
                grouping_key_obj.grouping_key = grouping_key
                grouping_key_obj.save()
            else:
                hook_log.create_grouping_key(service_name, grouping_key)
    except IntegrityError:
        # do something
        pass
``` oh!! I find when I create the Database object, I can set autorollback flag to True, it is useful. Yes, you can definitely use `autorollback`. This feature was requested by some users and although I do *not* like it, enough people have expressed interest that it is implemented.

I would never use it in my own code. Better to use explicit transactions around data-modifying code (`with db.atomic(): ...`).
I use mysqldb + peewee, when I update a row to trigger an IntegrityError on an unique key filed, first time, it is normal, but when second, it is in a mysql lock wait until timeout.
when i open the autocommit flag in the mysqldb, the problem is not appear recurrence, I think it is a bug.
i run the mysql 5.7.25 READ-COMMITED , mysql-python 1.2.3
this is my table define
``` sql
CREATE TABLE `groupingKey` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `serviceName` varchar(200) NOT NULL,
  `groupingKey` text NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `groupingKey_serviceName_uindex` (`serviceName`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8
```
my model defind
``` python
class GroupingKey(BaseModel):
    service_name = CharField(column_name='serviceName', unique=True, index=True)
    grouping_key = TextField(column_name='groupingKey')

    class Meta:
        table_name = 'groupingKey'
```

my code:
``` python
        try:
            if grouping_key_id:
                grouping_key_obj = hook_log.query_grouping_key_by_id(grouping_key_id)
                grouping_key_obj.service_name = service_name
                grouping_key_obj.grouping_key = grouping_key
                grouping_key_obj.save()
            else:
                hook_log.create_grouping_key(service_name, grouping_key)
        except IntegrityError:
            # do something
            pass
```
