[Patchew-devel] [PATCH] fix git Results that are incorrect empty strings

Paolo Bonzini posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20180711122455.21112-1-pbonzini@redhat.com
api/migrations/0028_populate_git_results.py |  4 ++--
api/migrations/0032_fix_git_results.py      | 20 ++++++++++++++++++++
mods/git.py                                 |  4 ++--
3 files changed, 24 insertions(+), 4 deletions(-)
create mode 100644 api/migrations/0032_fix_git_results.py
[Patchew-devel] [PATCH] fix git Results that are incorrect empty strings
Posted by Paolo Bonzini 5 years, 9 months ago
Due to an error in the migration to populate Results for git, the data
field was set to an empty string rather than an empty dictionary.  Fix
this with another migration on top.  For simplicity I am using raw SQL
here.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reported-by: Shubham Jain <shubhamjain7495@gmail.com>
---
 api/migrations/0028_populate_git_results.py |  4 ++--
 api/migrations/0032_fix_git_results.py      | 20 ++++++++++++++++++++
 mods/git.py                                 |  4 ++--
 3 files changed, 24 insertions(+), 4 deletions(-)
 create mode 100644 api/migrations/0032_fix_git_results.py

diff --git a/api/migrations/0028_populate_git_results.py b/api/migrations/0028_populate_git_results.py
index 482641a..bc17e08 100644
--- a/api/migrations/0028_populate_git_results.py
+++ b/api/migrations/0028_populate_git_results.py
@@ -34,6 +34,7 @@ def result_from_properties(apps, schema_editor):
             log_entry = LogEntry(data_xz=log_xz)
             log_entry.save()
             r.log_entry = log_entry
+            data = {}
             if get_property(MessageProperty, "git.apply-failed", message=m):
                 r.status = api.models.Result.FAILURE
             else:
@@ -41,7 +42,6 @@ def result_from_properties(apps, schema_editor):
                 git_tag = get_property(MessageProperty, "git.tag", message=m)
                 git_url = get_property(MessageProperty, "git.url", message=m)
                 git_base = get_property(MessageProperty, "git.base", message=m)
-                data = {}
                 if git_repo and git_tag:
                     data['repo'] = git_repo
                     data['tag'] = 'refs/tags/' + git_tag
@@ -49,8 +49,8 @@ def result_from_properties(apps, schema_editor):
                         data['url'] = git_url
                     if git_base:
                         data['base'] = git_base
-                r.data = data
                 r.status = api.models.Result.SUCCESS
+            r.data = data
         else:
             status = api.models.Result.PENDING
         r.last_update = datetime.datetime.utcnow()
diff --git a/api/migrations/0032_fix_git_results.py b/api/migrations/0032_fix_git_results.py
new file mode 100644
index 0000000..2438126
--- /dev/null
+++ b/api/migrations/0032_fix_git_results.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.13 on 2018-07-11 12:17
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('api', '0031_auto_20180520_1654'),
+    ]
+
+    operations = [
+        # Due to an error in the migration to populate Results for git, the data
+        # field was set to an empty string rather than an empty dictionary.  This
+        # has been fixed now in the migration, but the fix is also included as a
+        # separate migration in case the buggy data is found in the database.
+        migrations.RunSQL("update api_result set data = '{}' where name='git' and data = '\"\"'")
+    ]
diff --git a/mods/git.py b/mods/git.py
index a2b6d86..924547a 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -276,10 +276,10 @@ class ApplierReportView(APILoginRequiredView):
         r = Message.objects.series_heads().get(project=p,
                                                message_id=message_id).git_result
         r.log = log
+        data = {}
         if failed:
             r.status = Result.FAILURE
         else:
-            data = {}
             data['repo'] = repo
             data['tag'] = 'refs/tags/' + tag
             if url:
@@ -289,6 +289,6 @@ class ApplierReportView(APILoginRequiredView):
                 data['url'] = url_template.replace("%t", tag)
             if base:
                 data['base'] = base
-            r.data = data
             r.status = Result.SUCCESS
+        r.data = data
         r.save()
-- 
2.17.1

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel