We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Migration from 3.9.1 to 3.10 fails with AttributeError: 'Comment' object has no attribute '__getstate__'
**Describe the bug**
After upgrading to 3.10 (from 3.9.1) applying trans.0053_unitdata fails with an error.

```
  Applying trans.0053_unitdata...Traceback (most recent call last):
  File "/home/ubuntu/weblateenv/bin/weblate", line 11, in <module>
    sys.exit(main())
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/weblate/runner.py", line 34, in main
    execute_from_command_line(argv)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 193, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/weblate/trans/migrations/0053_unitdata.py", line 24, in migrate_unitdata
    state = obj.__getstate__()
AttributeError: 'Comment' object has no attribute '__getstate__'
Sentry is attempting to send 1 pending error messages
Waiting up to 10 seconds
```

**To Reproduce**
Steps to reproduce the behavior:
1. have 3.9.1 installed
1. upgrade to 3.10 via pip
1. apply changes to the settings.py file
1. run `weblate migrate`
1. see the error (https://sentry.io/share/issue/8e9bee713ce74fc9b53d800b504dcfa5/)

**Expected behavior**
no error and a working migration

**Logs**
https://sentry.io/share/issue/8e9bee713ce74fc9b53d800b504dcfa5/

**Server configuration and status**
output of `weblate list_versions`:
```
 * Weblate: 3.10
 * Django: 1.11.11
 * siphashc: 1.2
 * Whoosh: 2.7.4
 * translate-toolkit: 2.4.0
 * lxml: 4.2.1
 * Pillow: 6.2.1
 * bleach: 3.1.0
 * six: 1.13.0
 * python-dateutil: 2.8.1
 * social-auth-core: 3.2.0
 * social-auth-app-django: 3.1.0
 * django-crispy-forms: 1.8.1
 * oauthlib: 3.1.0
 * django-compressor: 2.3
 * djangorestframework: 3.9.0
 * django-appconf: 1.0.3
 * user-agents: 2.0
 * filelock: 3.0.12
 * setuptools: 39.0.1
 * jellyfish: 0.6.1
 * openpyxl: 2.6.4
 * celery: 4.3.0
 * kombu: 4.6.7
 * celery-batches: 0.2
 * translation-finder: 1.7
 * html2text: 2019.8.11
 * pycairo: 1.18.2
 * pygobject: 3.34.0
 * diff-match-patch: 20181111
 * requests: 2.22.0
 * django-redis: 4.10.0
 * hiredis: 1.0.1
 * sentry_sdk: 0.13.5
 * Cython: 0.29.14
 * misaka: 2.1.1
 * GitPython: 2.1.14
 * Python: 2.7.12
 * Git: 2.7.4
 * phply: 1.2.4
 * chardet: 3.0.4
 * ruamel.yaml: 0.16.5
 * Database backends: django.db.backends.mysql
 * Cache backends: default:RedisCache, avatar:FileBasedCache
 * Email setup: django.core.mail.backends.smtp.EmailBackend: smtp.mailgun.org
 * Celery: redis://127.0.0.1:6379/0, redis://127.0.0.1:6379/0, regular
 * Platform: Linux 4.4.0-1049-aws (x86_64)
```

output of `weblate check --deploy`:
```
SystemCheckError: System check identified some issues:

ERRORS:
?: (weblate.E006) Please migrate your database to use PostgreSQL. Support for other database backends will be dropped in Weblate 4.0 currently sheduled on April 2020.
	HINT: https://docs.weblate.org/en/weblate-3.10/admin/install.html#production-database
?: (weblate.W023) Please upgrade your installation to Python 3. Python 2 support will be dropped in Weblate 4.0 currently sheduled on April 2020.
	HINT: https://docs.weblate.org/en/weblate-3.10/admin/upgrade.html#py3

System check identified 2 issues (7 silenced).
```


Not quite sure how to fix this.
Thanks in advance!


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `weblate/trans/migrations/0053_unitdata.py`
Content:
```
1 # Generated by Django 2.2.5 on 2019-12-12 14:12
2 
3 from django.db import migrations
4 
5 MODELS = [("trans", "Comment"), ("trans", "Suggestion"), ("checks", "Check")]
6 
7 
8 def migrate_unitdata(apps, schema_editor):
9     db_alias = schema_editor.connection.alias
10 
11     Unit = apps.get_model("trans", "Unit")
12 
13     for model in (apps.get_model(*args) for args in MODELS):
14         # Create new objects for each related unit
15         for obj in model.objects.using(db_alias).filter(unit=None).iterator():
16             units = Unit.objects.using(db_alias).filter(
17                 content_hash=obj.content_hash,
18                 translation__component__project=obj.project,
19             )
20             if obj.language is None:
21                 units = units.filter(translation__language=obj.project.source_language)
22             else:
23                 units = units.filter(translation__language=obj.language)
24             # Using __getstate__ would be cleaner, but needs Django 2.0
25             state = dict(obj.__dict__)
26             del state["_state"]
27             del state["id"]
28             del state["unit_id"]
29             for unit in units:
30                 if model.objects.using(db_alias).filter(unit=unit, **state).exists():
31                     continue
32                 model.objects.using(db_alias).create(unit=unit, **state)
33 
34         # Remove old objects without unit link
35         model.objects.using(db_alias).filter(unit=None).delete()
36 
37 
38 class Migration(migrations.Migration):
39 
40     dependencies = [("trans", "0052_auto_20191212_1403"), ("checks", "0002_check_unit")]
41 
42     operations = [
43         migrations.RunPython(migrate_unitdata, migrations.RunPython.noop, elidable=True)
44     ]
45
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/weblate/trans/migrations/0053_unitdata.py b/weblate/trans/migrations/0053_unitdata.py
--- a/weblate/trans/migrations/0053_unitdata.py
+++ b/weblate/trans/migrations/0053_unitdata.py
@@ -2,7 +2,25 @@
 
 from django.db import migrations
 
-MODELS = [("trans", "Comment"), ("trans", "Suggestion"), ("checks", "Check")]
+MODELS = [
+    (
+        ("trans", "Comment"),
+        ("content_hash", "project", "language", "comment", "user", "timestamp"),
+    ),
+    (
+        ("trans", "Suggestion"),
+        (
+            "content_hash",
+            "project",
+            "language",
+            "target",
+            "user",
+            "userdetails",
+            "timestamp",
+        ),
+    ),
+    (("checks", "Check"), ("content_hash", "project", "language", "check", "ignore")),
+]
 
 
 def migrate_unitdata(apps, schema_editor):
@@ -10,7 +28,8 @@
 
     Unit = apps.get_model("trans", "Unit")
 
-    for model in (apps.get_model(*args) for args in MODELS):
+    for model_args, fields in MODELS:
+        model = apps.get_model(*model_args)
         # Create new objects for each related unit
         for obj in model.objects.using(db_alias).filter(unit=None).iterator():
             units = Unit.objects.using(db_alias).filter(
@@ -22,14 +41,15 @@
             else:
                 units = units.filter(translation__language=obj.language)
             # Using __getstate__ would be cleaner, but needs Django 2.0
-            state = dict(obj.__dict__)
-            del state["_state"]
-            del state["id"]
-            del state["unit_id"]
+            state = {field: getattr(obj, field) for field in fields}
             for unit in units:
                 if model.objects.using(db_alias).filter(unit=unit, **state).exists():
                     continue
-                model.objects.using(db_alias).create(unit=unit, **state)
+                created = model.objects.using(db_alias).create(unit=unit, **state)
+                # Migrate suggestion votes
+                if model_args == ("trans", "Suggestion"):
+                    for vote in obj.vote_set.all():
+                        created.vote_set.create(user=vote.user, value=vote.value)
 
         # Remove old objects without unit link
         model.objects.using(db_alias).filter(unit=None).delete()

{"golden_diff": "diff --git a/weblate/trans/migrations/0053_unitdata.py b/weblate/trans/migrations/0053_unitdata.py\n--- a/weblate/trans/migrations/0053_unitdata.py\n+++ b/weblate/trans/migrations/0053_unitdata.py\n@@ -2,7 +2,25 @@\n \n from django.db import migrations\n \n-MODELS = [(\"trans\", \"Comment\"), (\"trans\", \"Suggestion\"), (\"checks\", \"Check\")]\n+MODELS = [\n+    (\n+        (\"trans\", \"Comment\"),\n+        (\"content_hash\", \"project\", \"language\", \"comment\", \"user\", \"timestamp\"),\n+    ),\n+    (\n+        (\"trans\", \"Suggestion\"),\n+        (\n+            \"content_hash\",\n+            \"project\",\n+            \"language\",\n+            \"target\",\n+            \"user\",\n+            \"userdetails\",\n+            \"timestamp\",\n+        ),\n+    ),\n+    ((\"checks\", \"Check\"), (\"content_hash\", \"project\", \"language\", \"check\", \"ignore\")),\n+]\n \n \n def migrate_unitdata(apps, schema_editor):\n@@ -10,7 +28,8 @@\n \n     Unit = apps.get_model(\"trans\", \"Unit\")\n \n-    for model in (apps.get_model(*args) for args in MODELS):\n+    for model_args, fields in MODELS:\n+        model = apps.get_model(*model_args)\n         # Create new objects for each related unit\n         for obj in model.objects.using(db_alias).filter(unit=None).iterator():\n             units = Unit.objects.using(db_alias).filter(\n@@ -22,14 +41,15 @@\n             else:\n                 units = units.filter(translation__language=obj.language)\n             # Using __getstate__ would be cleaner, but needs Django 2.0\n-            state = dict(obj.__dict__)\n-            del state[\"_state\"]\n-            del state[\"id\"]\n-            del state[\"unit_id\"]\n+            state = {field: getattr(obj, field) for field in fields}\n             for unit in units:\n                 if model.objects.using(db_alias).filter(unit=unit, **state).exists():\n                     continue\n-                model.objects.using(db_alias).create(unit=unit, **state)\n+                created = model.objects.using(db_alias).create(unit=unit, **state)\n+                # Migrate suggestion votes\n+                if model_args == (\"trans\", \"Suggestion\"):\n+                    for vote in obj.vote_set.all():\n+                        created.vote_set.create(user=vote.user, value=vote.value)\n \n         # Remove old objects without unit link\n         model.objects.using(db_alias).filter(unit=None).delete()\n", "issue": "Migration from 3.9.1 to 3.10 fails with AttributeError: 'Comment' object has no attribute '__getstate__'\n**Describe the bug**\r\nAfter upgrading to 3.10 (from 3.9.1) applying trans.0053_unitdata fails with an error.\r\n\r\n```\r\n  Applying trans.0053_unitdata...Traceback (most recent call last):\r\n  File \"/home/ubuntu/weblateenv/bin/weblate\", line 11, in <module>\r\n    sys.exit(main())\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/weblate/runner.py\", line 34, in main\r\n    execute_from_command_line(argv)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 356, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/base.py\", line 283, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/base.py\", line 330, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py\", line 204, in handle\r\n    fake_initial=fake_initial,\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 115, in migrate\r\n    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 145, in _migrate_all_forwards\r\n    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 244, in apply_migration\r\n    state = migration.apply(state, schema_editor)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/migration.py\", line 126, in apply\r\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py\", line 193, in database_forwards\r\n    self.code(from_state.apps, schema_editor)\r\n  File \"/home/ubuntu/weblateenv/local/lib/python2.7/site-packages/weblate/trans/migrations/0053_unitdata.py\", line 24, in migrate_unitdata\r\n    state = obj.__getstate__()\r\nAttributeError: 'Comment' object has no attribute '__getstate__'\r\nSentry is attempting to send 1 pending error messages\r\nWaiting up to 10 seconds\r\n```\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. have 3.9.1 installed\r\n1. upgrade to 3.10 via pip\r\n1. apply changes to the settings.py file\r\n1. run `weblate migrate`\r\n1. see the error (https://sentry.io/share/issue/8e9bee713ce74fc9b53d800b504dcfa5/)\r\n\r\n**Expected behavior**\r\nno error and a working migration\r\n\r\n**Logs**\r\nhttps://sentry.io/share/issue/8e9bee713ce74fc9b53d800b504dcfa5/\r\n\r\n**Server configuration and status**\r\noutput of `weblate list_versions`:\r\n```\r\n * Weblate: 3.10\r\n * Django: 1.11.11\r\n * siphashc: 1.2\r\n * Whoosh: 2.7.4\r\n * translate-toolkit: 2.4.0\r\n * lxml: 4.2.1\r\n * Pillow: 6.2.1\r\n * bleach: 3.1.0\r\n * six: 1.13.0\r\n * python-dateutil: 2.8.1\r\n * social-auth-core: 3.2.0\r\n * social-auth-app-django: 3.1.0\r\n * django-crispy-forms: 1.8.1\r\n * oauthlib: 3.1.0\r\n * django-compressor: 2.3\r\n * djangorestframework: 3.9.0\r\n * django-appconf: 1.0.3\r\n * user-agents: 2.0\r\n * filelock: 3.0.12\r\n * setuptools: 39.0.1\r\n * jellyfish: 0.6.1\r\n * openpyxl: 2.6.4\r\n * celery: 4.3.0\r\n * kombu: 4.6.7\r\n * celery-batches: 0.2\r\n * translation-finder: 1.7\r\n * html2text: 2019.8.11\r\n * pycairo: 1.18.2\r\n * pygobject: 3.34.0\r\n * diff-match-patch: 20181111\r\n * requests: 2.22.0\r\n * django-redis: 4.10.0\r\n * hiredis: 1.0.1\r\n * sentry_sdk: 0.13.5\r\n * Cython: 0.29.14\r\n * misaka: 2.1.1\r\n * GitPython: 2.1.14\r\n * Python: 2.7.12\r\n * Git: 2.7.4\r\n * phply: 1.2.4\r\n * chardet: 3.0.4\r\n * ruamel.yaml: 0.16.5\r\n * Database backends: django.db.backends.mysql\r\n * Cache backends: default:RedisCache, avatar:FileBasedCache\r\n * Email setup: django.core.mail.backends.smtp.EmailBackend: smtp.mailgun.org\r\n * Celery: redis://127.0.0.1:6379/0, redis://127.0.0.1:6379/0, regular\r\n * Platform: Linux 4.4.0-1049-aws (x86_64)\r\n```\r\n\r\noutput of `weblate check --deploy`:\r\n```\r\nSystemCheckError: System check identified some issues:\r\n\r\nERRORS:\r\n?: (weblate.E006) Please migrate your database to use PostgreSQL. Support for other database backends will be dropped in Weblate 4.0 currently sheduled on April 2020.\r\n\tHINT: https://docs.weblate.org/en/weblate-3.10/admin/install.html#production-database\r\n?: (weblate.W023) Please upgrade your installation to Python 3. Python 2 support will be dropped in Weblate 4.0 currently sheduled on April 2020.\r\n\tHINT: https://docs.weblate.org/en/weblate-3.10/admin/upgrade.html#py3\r\n\r\nSystem check identified 2 issues (7 silenced).\r\n```\r\n\r\n\r\nNot quite sure how to fix this.\r\nThanks in advance!\r\n\n", "before_files": [{"content": "# Generated by Django 2.2.5 on 2019-12-12 14:12\n\nfrom django.db import migrations\n\nMODELS = [(\"trans\", \"Comment\"), (\"trans\", \"Suggestion\"), (\"checks\", \"Check\")]\n\n\ndef migrate_unitdata(apps, schema_editor):\n    db_alias = schema_editor.connection.alias\n\n    Unit = apps.get_model(\"trans\", \"Unit\")\n\n    for model in (apps.get_model(*args) for args in MODELS):\n        # Create new objects for each related unit\n        for obj in model.objects.using(db_alias).filter(unit=None).iterator():\n            units = Unit.objects.using(db_alias).filter(\n                content_hash=obj.content_hash,\n                translation__component__project=obj.project,\n            )\n            if obj.language is None:\n                units = units.filter(translation__language=obj.project.source_language)\n            else:\n                units = units.filter(translation__language=obj.language)\n            # Using __getstate__ would be cleaner, but needs Django 2.0\n            state = dict(obj.__dict__)\n            del state[\"_state\"]\n            del state[\"id\"]\n            del state[\"unit_id\"]\n            for unit in units:\n                if model.objects.using(db_alias).filter(unit=unit, **state).exists():\n                    continue\n                model.objects.using(db_alias).create(unit=unit, **state)\n\n        # Remove old objects without unit link\n        model.objects.using(db_alias).filter(unit=None).delete()\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [(\"trans\", \"0052_auto_20191212_1403\"), (\"checks\", \"0002_check_unit\")]\n\n    operations = [\n        migrations.RunPython(migrate_unitdata, migrations.RunPython.noop, elidable=True)\n    ]\n", "path": "weblate/trans/migrations/0053_unitdata.py"}], "after_files": [{"content": "# Generated by Django 2.2.5 on 2019-12-12 14:12\n\nfrom django.db import migrations\n\nMODELS = [\n    (\n        (\"trans\", \"Comment\"),\n        (\"content_hash\", \"project\", \"language\", \"comment\", \"user\", \"timestamp\"),\n    ),\n    (\n        (\"trans\", \"Suggestion\"),\n        (\n            \"content_hash\",\n            \"project\",\n            \"language\",\n            \"target\",\n            \"user\",\n            \"userdetails\",\n            \"timestamp\",\n        ),\n    ),\n    ((\"checks\", \"Check\"), (\"content_hash\", \"project\", \"language\", \"check\", \"ignore\")),\n]\n\n\ndef migrate_unitdata(apps, schema_editor):\n    db_alias = schema_editor.connection.alias\n\n    Unit = apps.get_model(\"trans\", \"Unit\")\n\n    for model_args, fields in MODELS:\n        model = apps.get_model(*model_args)\n        # Create new objects for each related unit\n        for obj in model.objects.using(db_alias).filter(unit=None).iterator():\n            units = Unit.objects.using(db_alias).filter(\n                content_hash=obj.content_hash,\n                translation__component__project=obj.project,\n            )\n            if obj.language is None:\n                units = units.filter(translation__language=obj.project.source_language)\n            else:\n                units = units.filter(translation__language=obj.language)\n            # Using __getstate__ would be cleaner, but needs Django 2.0\n            state = {field: getattr(obj, field) for field in fields}\n            for unit in units:\n                if model.objects.using(db_alias).filter(unit=unit, **state).exists():\n                    continue\n                created = model.objects.using(db_alias).create(unit=unit, **state)\n                # Migrate suggestion votes\n                if model_args == (\"trans\", \"Suggestion\"):\n                    for vote in obj.vote_set.all():\n                        created.vote_set.create(user=vote.user, value=vote.value)\n\n        # Remove old objects without unit link\n        model.objects.using(db_alias).filter(unit=None).delete()\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [(\"trans\", \"0052_auto_20191212_1403\"), (\"checks\", \"0002_check_unit\")]\n\n    operations = [\n        migrations.RunPython(migrate_unitdata, migrations.RunPython.noop, elidable=True)\n    ]\n", "path": "weblate/trans/migrations/0053_unitdata.py"}]}