-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
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
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 |
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