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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions wagtail_transfer/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

# 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 :-)


try:
Expand Down