wagtail / wagtail-transfer

Content transfer for Wagtail

Home Page:https://wagtail.github.io/wagtail-transfer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding `'wagtailcore.page' to WAGTAILTRANSFER_LOOKUP_FIELDS causes error trying to match in admin

easherma-truth opened this issue · comments

I don’t think there was ever an expectation that WAGTAILTRANSFER_LOOKUP_FIELDS would be used for looking up the page model, but nothing prevents that from happening either.

However, with this setting on import the admin will fail to find the correct matching page.

#132 proposes a change to allow this, though please consider it just a starting place for discussion as it may not be the best place to make the change (and probably merits some test coverage, ideally)

To replicate

  1. Have an instance set up with the above setting included in WAGTAILTRANSFER_LOOKUP_FIELDS
  2. Open the admin view and go to import
  3. Notice you'll get an error like ValueError: Field 'id' expected a number but got 'e'. when trying to choose the page to import
  4. This is because in that case uid is getting passed along as a string instead of a tuple, so it can't match based on that because it gets parsed incorrectly

Hey Eric,

We ran into this issue as well because we wanted to use url_path to look up pages:

WAGTAILTRANSFER_LOOKUP_FIELDS = {
    …
    "wagtailcore.Page": ["url_path"],
}

As we were on a tight deadline to make use of this, we implemented a very similar fix in a fork, intending to PR it back of course, but just never got around to it.

Would love to work together and settle on the best approach. /cc @addisonhardy

Also interested in input from the wagtail-transfer creators on why this sort of approach wasn't taken in the first place, given that maintaining links to / choices of pages on transfer seems pretty highly desirable.

Looks like at least some related discussion and context in the commit messages on this branch: #15

@Scotchester one idea I'm also considering that I wonder if ya'll considered:

def check_page_existence_for_uid(request):
    """
    Check whether a page with the specified UID exists - used for checking whether a page has already been imported
    to the destination site
    """
    uid = request.GET.get('uid', '').split(',')

this seems to work without changes to locators.py that we both jumped to

But that only works if the page has already been imported? The reason we went down this road was to handle links/choosers to non-imported pages that already exist.

@Scotchester right, thanks for the reminder! :-D