From patchwork Thu Oct 1 14:52:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 525078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8E250140D16 for ; Fri, 2 Oct 2015 00:53:36 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 6C1731A010A for ; Fri, 2 Oct 2015 00:53:36 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lists.ozlabs.org (Postfix) with ESMTP id 467711A0320 for ; Fri, 2 Oct 2015 00:52:56 +1000 (AEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 01 Oct 2015 07:52:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,618,1437462000"; d="scan'208";a="817157149" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 01 Oct 2015 07:52:42 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t91Eqehx005358; Thu, 1 Oct 2015 15:52:40 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t91EqeqG019612; Thu, 1 Oct 2015 15:52:40 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t91Eqet3019607; Thu, 1 Oct 2015 15:52:40 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 01/10] models: Resolve issues with Patch.state Date: Thu, 1 Oct 2015 15:52:25 +0100 Message-Id: <1443711154-18689-2-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1443711154-18689-1-git-send-email-stephen.finucane@intel.com> References: <1443711154-18689-1-git-send-email-stephen.finucane@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" The initial migration was incomplete: running 'makemigrations' on the current codebase would produce a migration which could not be applied. Fix this issue and add a suitable migration to resolve the issue henceforth. Signed-off-by: Stephen Finucane Acked-by: Damien Lespiau --- patchwork/migrations/0001_initial.py | 2 +- .../migrations/0002_fix_patch_state_default_values.py | 19 +++++++++++++++++++ patchwork/models.py | 8 +++----- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 patchwork/migrations/0002_fix_patch_state_default_values.py diff --git a/patchwork/migrations/0001_initial.py b/patchwork/migrations/0001_initial.py index 65d1c35..812558a 100644 --- a/patchwork/migrations/0001_initial.py +++ b/patchwork/migrations/0001_initial.py @@ -2,12 +2,12 @@ from __future__ import unicode_literals from django.db import models, migrations -from django.core.management import call_command import datetime import patchwork.models import django.db.models.deletion from django.conf import settings + class Migration(migrations.Migration): dependencies = [ diff --git a/patchwork/migrations/0002_fix_patch_state_default_values.py b/patchwork/migrations/0002_fix_patch_state_default_values.py new file mode 100644 index 0000000..4887935 --- /dev/null +++ b/patchwork/migrations/0002_fix_patch_state_default_values.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='patch', + name='state', + field=models.ForeignKey(to='patchwork.State', null=True), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index c2b8a9c..0c8022c 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -243,7 +243,7 @@ class Patch(models.Model): date = models.DateTimeField(default=datetime.datetime.now) submitter = models.ForeignKey(Person) delegate = models.ForeignKey(User, blank = True, null = True) - state = models.ForeignKey(State, default=get_default_initial_patch_state) + state = models.ForeignKey(State, null=True) archived = models.BooleanField(default = False) headers = models.TextField(blank = True) content = models.TextField(null = True, blank = True) @@ -279,10 +279,8 @@ class Patch(models.Model): self._set_tag(tag, counter[tag]) def save(self): - try: - s = self.state - except: - self.state = State.objects.get(ordering = 0) + if not hasattr(self, 'state') or not self.state: + self.state = get_default_initial_patch_state() if self.hash is None and self.content is not None: self.hash = hash_patch(self.content).hexdigest()