[PATCH v2 01/10] models: Resolve issues with Patch.state
Finucane, Stephen
stephen.finucane at intel.com
Fri Oct 2 01:14:23 AEST 2015
> On Thu, Oct 01, 2015 at 03:52:25PM +0100, Stephen Finucane wrote:
> > @@ -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)
>
> I was wondering, is it necessary to change the null contraint here?
To the best of my knowledge, yes. We need a default but we don't always have any entries in the 'State' table (for example, when testing). As a result the only possible "default" is None. Note that this will never be set to a null value however due to the additions to the 'save' function.
> --
> Damien
>
> > 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()
> > --
> > 2.0.0
> >
> > _______________________________________________
> > Patchwork mailing list
> > Patchwork at lists.ozlabs.org
> > https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list