def save(self, *args, **kwargs): if not hasattr(self, 'state') or not self.state: self.state = get_default_initial_patch_state() if self.hash is None and self.diff is not None: self.hash = hash_diff(self.diff) super(Patch, self).save(**kwargs) self.refresh_tag_counts()