Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check uid type in Field Locator and handle if str #132

Closed
wants to merge 1 commit into from

Conversation

easherma-truth
Copy link

@easherma-truth easherma-truth commented Dec 20, 2022

Fixes #133 Currently nothing prevents a setup like WAGTAILTRANSFER_LOOKUP_FIELDS = {'wagtailcore.page': ['slug', 'locale_id']} from existing, but this will cause issues trying to look up and match the page due to how it's currently sent in the admin_url

Currently nothing prevents a setup like ```WAGTAILTRANSFER_LOOKUP_FIELDS = {'wagtailcore.page': ['slug', 'locale_id']}``` from existing, 
but this will cause issues trying to look up and match the page due to how it's currently sent in the admin_url
Copy link
Member

@emilytoppm emilytoppm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition! A few suggestions, and it would be great to add some test coverage

elif type(uid) == str:
# if lookup fields are configured for wagtailcore.page, then in the admin view those
# fields get passed along as a string
filters = dict(zip(self.fields, uid.split(",")))
filters = dict(zip(self.fields, uid))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this line would just override the new filters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, that may just be a typo from when I copied my tested changes over to the patch :-)

@@ -127,6 +127,12 @@ def uid_from_json(self, json_uid):
def find(self, uid):
# pair up field names with their respective items in the UID tuple, to form a filter dict
# that we can use for an ORM lookup
if type(uid) == tuple:
filters = dict(zip(self.fields, uid))
elif type(uid) == str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this issue only occur here: https://github.com/wagtail/wagtail-transfer/blob/main/wagtail_transfer/views.py#L314? In which case, I think it might be better for this method to assume a consistent type to the uid argument, and for the view/some other utility method to handle conversion

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although that is one place where I found the bug in practice, I'm not sure what the full implications would be for the rest of the codebase in using lookup field values for pages. But I agree if this is the only place that some sort of more testable utility method would be nice, but I'd need to either explore the codebase more or have help speccing that out to be confident in a solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, it sounds like the key problem that this is solving is UID in query params (there may be other issues, but I think this fix only addresses that?). What happens if you change request.GET.get to request.GET.getlist? I'm wondering if that may solve the issue too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try playing with request.GET.getlist more, but at first test it didn't change the error

@easherma-truth easherma-truth deleted the patch-1 branch January 3, 2023 18:09
@easherma-truth
Copy link
Author

oh thats annoying, I tried to rename the branch to be more descriptive and it closed and deleted it :-D

I'll link to new PR so we can keep the discussion going

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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