Skip to content

Copy fails for a Wagtail page with no tags #134

@higs4281

Description

@higs4281

We've been getting server errors when pages without tags are copied.

I think I've traced the problem to contrib/taggit.py, where the passed tags value is a tuple consisting of an empty FakeQuerySet instance, which raises a ValueError such as this:

ValueError: Cannot add [] (<class 'modelcluster.queryset.FakeQuerySet'>). Expected <class 'django.db.models.base.ModelBase'> or str.

I can get the process to complete without error by adding this check to _ClusterTaggableManager's add method:

    def add(self, *tags):
        if not tags[0]:
            return
        if TAGGIT_VERSION >= (1, 3, 0):
            tag_objs = self._to_tag_model_instances(tags, {})
        else:
            tag_objs = self._to_tag_model_instances(tags)

If this is acceptable, and isn't a known issue or something that would be better addressed elsewhere, I'd be happy to open a PR.

We are running these versions:

  • wagtail==2.10.1
  • Django==2.2.16
  • Python 3.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions