Skip to content

Commit

Permalink
fix git Results that are incorrect empty strings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bonzini authored and shubhamdotjain committed Aug 6, 2018
1 parent 097c27d commit 5fe69c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions api/migrations/0028_populate_git_results.py
Expand Up @@ -34,23 +34,23 @@ 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:
git_repo = get_property(MessageProperty, "git.repo", message=m)
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
if git_url:
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()
Expand Down
20 changes: 20 additions & 0 deletions 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 = '\"\"'")
]
4 changes: 2 additions & 2 deletions mods/git.py
Expand Up @@ -276,10 +276,10 @@ def handle(self, request, project, message_id, tag, url, base, repo,
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:
Expand All @@ -289,6 +289,6 @@ def handle(self, request, project, message_id, tag, url, base, repo,
data['url'] = url_template.replace("%t", tag)
if base:
data['base'] = base
r.data = data
r.status = Result.SUCCESS
r.data = data
r.save()

0 comments on commit 5fe69c8

Please sign in to comment.