Comments (7)
Addendum: They copy action does result in a copied page despite the server errors, but its new title doesn't show in the Wagtail admin.
from django-modelcluster.
Hi @higs4281,
Please can you provide steps to reproduce this error independently? As far as I can see, passing a queryset to a TaggableManager's add
method is not valid, so django-taggit's _to_tag_model_instances
method is correctly rejecting it. If this is happening from within Wagtail code then that would be a bug to be investigated and fixed within Wagtail - however, when I test against the bakerydemo project (creating a blog post with no tags, then copying it) the copy succeeds with no error, so I suspect this is something specific to your project.
from django-modelcluster.
I need to do more digging, because I now find that I get the error on pages with tags, so this does seem like an implementation issue. Thanks for the quick response. I can close this until I know more.
from django-modelcluster.
Hi,
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:
I am facing exactly the same issue, with or without tags on specific page models. Here follow a textual stack trace and the visual one with more details.
Internal Server Error: /admin/pages/27/copy/
Traceback (most recent call last):
File "venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "venv/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "venv/lib/python3.9/site-packages/wagtail/admin/urls/__init__.py", line 127, in wrapper
return view_func(request, *args, **kwargs)
File "venv/lib/python3.9/site-packages/wagtail/admin/auth.py", line 193, in decorated_view
return view_func(request, *args, **kwargs)
File "venv/lib/python3.9/site-packages/wagtail/admin/auth.py", line 60, in wrapped_view_func
return view_func(request, *args, **kwargs)
File "venv/lib/python3.9/site-packages/wagtail/admin/views/pages/copy.py", line 64, in copy
new_page = page.specific.copy(
File "venv/lib/python3.9/site-packages/wagtail/core/models.py", line 2053, in copy
_copy_m2m_relations(specific_self, page_copy, exclude_fields=exclude_fields, update_attrs=base_update_attrs)
File "venv/lib/python3.9/site-packages/wagtail/core/models.py", line 140, in _copy_m2m_relations
getattr(target, field.name).set(value)
File "venv/lib/python3.9/site-packages/taggit/utils.py", line 124, in inner
return func(self, *args, **kwargs)
File "venv/lib/python3.9/site-packages/modelcluster/contrib/taggit.py", line 78, in set
return super(_ClusterTaggableManager, self).set(*tags, clear=True)
File "venv/lib/python3.9/site-packages/taggit/utils.py", line 124, in inner
return func(self, *args, **kwargs)
File "venv/lib/python3.9/site-packages/taggit/managers.py", line 272, in set
self.add(*tags, **kwargs)
File "venv/lib/python3.9/site-packages/taggit/utils.py", line 124, in inner
return func(self, *args, **kwargs)
File "venv/lib/python3.9/site-packages/modelcluster/contrib/taggit.py", line 45, in add
tag_objs = self._to_tag_model_instances(tags, {})
File "venv/lib/python3.9/site-packages/taggit/managers.py", line 205, in _to_tag_model_instances
raise ValueError(
ValueError: Cannot add [<Tag: plop>, <Tag: plip>] (<class 'modelcluster.queryset.FakeQuerySet'>). Expected <class 'django.db.models.base.ModelBase'> or str.
[10/Sep/2021 14:54:35] "POST /admin/pages/27/copy/ HTTP/1.1" 500 134999
Software versions:
- django-modelcluster 5.1
- django-taggit 1.3.0
- wagtail 2.11.8
Best regards.
François
from django-modelcluster.
If that helps, the SitePage(Page)
's field mots_cles
has been defined using:
mots_cles = ClusterTaggableManager(
"Mots clés",
through='MotsClesTag',
blank=True,
related_name='tags',
)
with
class MotsClesTag(TaggedItemBase):
content_object = ParentalKey(
'SitePage', on_delete=models.CASCADE, related_name='tagged_items'
)
It may be tricky to build a minimal example reproducing the bug, but if it's definitly needed I may try.
from django-modelcluster.
FYI, we rather cheaply sidestepped the issue by editing our base page model to add tags and authors (another tag type for us) to the default_exclude_fields_in_copy
list that is declared on the Wagtail base Page model. This stopped server errors and gave editors a clean copy work flow.
This keeps tags and author tags out of the admin request cycle, but tags and authors still get applied to the copied page.
default_exclude_fields_in_copy = Page.default_exclude_fields_in_copy + [
'tags',
'authors'
]
from django-modelcluster.
default_exclude_fields_in_copy
It seems that the stable interface is exclude_fields_in_copy
.
from django-modelcluster.
Related Issues (20)
- KeyError in a del HOT 8
- Multi table inheritance - ptr_id fields not being restored
- Using TaggedItem in ClusterTaggableManager causing AttributeError HOT 1
- Unable to `prefetch_related` on `ClusterTaggableManager` HOT 1
- When I Modify Elements via Admin Panel , Its not getting Saved HOT 1
- Add support for Django 3.2 HOT 3
- ClusterForm.as_p should return a safe string
- test suite fails with django-taggit >= 2.0.0 HOT 1
- Nested ClusterableModel relations are not copied HOT 1
- AttributeError when a ParentalKey related manager is used as the queryset for a ModelChoiceField HOT 3
- Wagtail 3.0 support planned? HOT 2
- GenericForeignKey
- Django 5.0 support HOT 1
- Filtering on related manager when using `prefetch_related` with explicit `queryset` on a ClusterableModel returns wrong results HOT 1
- Field with the same name as a lookup in `FILTER_EXPRESSION_TOKENS` causes crash when filtering with implicit `exact`
- test_formfield_callback failing with Django 4.2 HOT 1
- Docs: please provide an example of a through model with a ParentalManyToManyField
- Unhelpful messaging when model attribute name shadows child relation
- Preview breaks on latest 6.2 version HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-modelcluster.