Repository: modoboa/modoboa

Issue:
handle_mailbox_operations cronjob fails
# Impacted versions

* Modoboa:1.13.1
* installer used: Yes
* Webserver: Nginx

# Steps to reproduce
As user `modoboa`:
`source env/bin/activate`
`python manage.py handle_mailbox_operations`

# Current behavior

On Wednesday the cronjob `handle_mailbox_operations` stopped working and throw the following error. We haven't done any maintenance or something on this day.

```Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/srv/modoboa/env/lib/python2.7/site-packages/modoboa/admin/management/commands/handle_mailbox_operations.py", line 106, in handle
    self.logger.info("%s succeed", ope)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1149, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/srv/modoboa/env/lib/python2.7/site-packages/modoboa/core/loggers.py", line 15, in emit
    logger=record.name
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/query.py", line 394, in create
    obj.save(force_insert=True, using=self.db)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/base.py", line 808, in save
    force_update=force_update, update_fields=update_fields)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/base.py", line 838, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/base.py", line 924, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/base.py", line 963, in _do_insert
    using=using, raw=raw)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/query.py", line 1079, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
    cursor.execute(sql, params)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/srv/modoboa/env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: FEHLER:  Wert zu lang für Typ character varying(255)
```

# Expected behavior
i think the cronjob should exit without any error. 

Thanks for your help! :)



Discussion:
@dpunkturban What's your database?
Hi @tonioo,

I am installed Modoboa with the official installer.

```
[root@mail01 ~]# postgres --version
postgres (PostgreSQL) 9.2.24
``` 
```
DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'modoboa',
        'USER': 'modoboa',
        'PASSWORD': 'REMOVED',
        'HOST': '127.0.0.1',
        'PORT': '',
        'ATOMIC_REQUESTS': True,

    },

    'amavis': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'amavis',
        'USER': 'amavis',
        'PASSWORD': 'REMOVED',
        'HOST': '127.0.0.1',
        'PORT': '',
        'ATOMIC_REQUESTS': True,

    },

}
```

Thanks :)

Resolving patch:
diff --git a/modoboa/core/migrations/0017_auto_20190705_1045.py b/modoboa/core/migrations/0017_auto_20190705_1045.py
new file mode 100644
--- /dev/null
+++ b/modoboa/core/migrations/0017_auto_20190705_1045.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-07-05 08:45
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('core', '0016_auto_20180713_1014'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='log',
+            name='message',
+            field=models.TextField(),
+        ),
+        migrations.AlterField(
+            model_name='user',
+            name='language',
+            field=models.CharField(choices=[('br', 'breton'), ('cs', 'čeština'), ('de', 'deutsch'), ('en', 'english'), ('el_GR', 'ελληνικά'), ('es', 'español'), ('fr', 'français'), ('it', 'italiano'), ('ja_JP', '日本の'), ('nl', 'nederlands'), ('pt_PT', 'português'), ('pt_BR', 'português (BR)'), ('pl_PL', 'polski'), ('ro_RO', 'Română'), ('ru', 'русский'), ('sv', 'svenska'), ('tr_TR', 'türk'), ('zh_TW', '中文（台灣）')], default='en', help_text='Prefered language to display pages.', max_length=10, verbose_name='language'),
+        ),
+    ]
diff --git a/modoboa/core/models.py b/modoboa/core/models.py
--- a/modoboa/core/models.py
+++ b/modoboa/core/models.py
@@ -432,7 +432,7 @@ class Log(models.Model):
     """Simple log in database."""
 
     date_created = models.DateTimeField(auto_now_add=True)
-    message = models.CharField(max_length=255)
+    message = models.TextField()
     level = models.CharField(max_length=15)
     logger = models.CharField(max_length=30)
 


Test patch: