From patchwork Wed Jul 22 09:17:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 498471 X-Patchwork-Delegate: stephen.finucane@intel.com 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 3BC571402B8 for ; Wed, 22 Jul 2015 19:17:38 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 26EFB1A1D4C for ; Wed, 22 Jul 2015 19:17:38 +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 A28761A1D1A for ; Wed, 22 Jul 2015 19:17:26 +1000 (AEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 22 Jul 2015 02:17:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,522,1432623600"; d="scan'208";a="733295403" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 22 Jul 2015 02:17:21 -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 t6M9HKfO024596; Wed, 22 Jul 2015 10:17:20 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t6M9HKEJ018310; Wed, 22 Jul 2015 10:17:20 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t6M9HKta018306; Wed, 22 Jul 2015 10:17:20 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] models: Resolve issues with Patch.state Date: Wed, 22 Jul 2015 10:17:13 +0100 Message-Id: <1437556633-18267-1-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 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 introduced in '30bb271' was incomplete: running 'makemigrations' on the current codebase will produce a migration which could not be applied cleanly. The reason for this was the non-loading of initial data for the 'State' model. Fix this issue by only referencing the contents of the 'State' model when we have to (on save of a 'Patch' object), thus allowing the user suitable time to apply this initial data. 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()