question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to extend exclude_fields for use when copying page

See original GitHub issue

Issue Summary

If your Page model contains relations that do not use ClusterableModel you cannot copy those pages in admin without causing an error. Adding the ability to define what fields must be excluded on copy per Page would enable working around this.

Steps to Reproduce

Note: This is my specific use case.

  1. Start a new Wagtail project
  2. Install Django Activity Stream http://django-activity-stream.readthedocs.io/en/latest/ pip install django-activity-stream
  3. In your main apps.py register a generic link to your Page model registry.register(Page) - http://django-activity-stream.readthedocs.io/en/latest/configuration.html
  4. Open a Page list in Admin and click More > Copy
  5. Change the Slug to something Unique
  6. Click ‘Copy this Page’

This results in the following Error: TypeError: ‘GenericRelatedObjectManager’ object is not iterable

The trace error is:
[09/Oct/2017 09:29:35] ERROR [django.request:135] Internal Server Error: /admin/pages/233/copy/
Traceback (most recent call last):
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 43, in _cache_controlled
    response = viewfunc(request, *args, **kw)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/decorators.py", line 31, in decorated_view
    return view_func(request, *args, **kwargs)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/utils.py", line 140, in wrapped_view_func
    return view_func(request, *args, **kwargs)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailadmin/views/pages.py", line 837, in copy
    user=request.user,
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailcore/models.py", line 1116, in copy
    page_copy = self.specific_class(**specific_dict)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/wagtail/wagtailcore/models.py", line 376, in __init__
    super(Page, self).__init__(*args, **kwargs)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/modelcluster/models.py", line 177, in __init__
    super(ClusterableModel, self).__init__(*args, **kwargs)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 567, in __init__
    _setattr(self, prop, kwargs[prop])
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py", line 537, in __set__
    manager.set(value)
  File "/home/ifeelgoogle/venv/local/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 613, in set
    objs = tuple(objs)
TypeError: 'GenericRelatedObjectManager' object is not iterable

Proposed Solution

https://github.com/wagtail/wagtail/blob/f15a98f983b1c6b11807d90226b7b3924b0a74d1/wagtail/wagtailcore/models.py#L1055

  • The line above: exclude_fields = ['id', 'path', 'depth', 'numchild', 'url_path', 'path']
  • Could be replaced with something like: self.excluded_fields_for_copy
  • The default would be the list above but this could be extended for a specific class like: excluded_fields_for_copy = Page.excluded_fields_for_copy + ['action_object_actions', 'actor_actions', 'target_actions']
  • As this is different to the exclude_fields used in modelAdmin it would need to be named specifically in relation to copying.

Technical details

  • Python 2.7.12
  • Django v.1.11.5
  • Wagtail v.1.12.2
  • Browser version: Chrome 61 on OS X 10.12.6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lb-commented, Oct 28, 2017

@gasman I will give a go at implementing this for a pull request next week.

0reactions
kaedrohocommented, Apr 3, 2019

Just hit this issue myself, the error message given doesn’t make it clear what’s going on. So I wonder if it’s worth excluding generic relations by default?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add/exclude fields to a form that extends another form
So I want to add date_of_birth to AnotherUserCreationForm and at the same time, I want to exclude role and is_staff in ...
Read more >
Add ability to exclude translatable fields from being handled ...
An entity may contain fields that hold data they are strictly for layout or presentation purposes.
Read more >
Exclude a table from cloning
The System Clone > Exclude Tables module lists the tables that are not copied during a system clone. By default, the system excludes...
Read more >
Copy and paste specific cell contents - Microsoft Support
Reorients the content of copied cells when pasting. Data in rows is pasted into columns and vice versa. Paste Values. Only the values...
Read more >
Mail merge: Edit recipients - Microsoft Support
The list of recipients Shows all the records that will be used in your mail merge. · Data Source Select Edit to change...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found