-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Proxito: adapt unresolver to make it usable for proxito #10037
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
Conversation
215718e
to
4f10484
Compare
fd683dd
to
9186199
Compare
9186199
to
c505544
Compare
This is ready for review. |
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.
These refactors are making the Proxito code better and better 💯
I left some comments to chat a little more about them and know if I'm understanding everything correctly here. Other than that, I think it's pretty close to be merged.
# We don't call unparse() on the path, | ||
# since it could be parsed as a full URL if it starts with a protocol. | ||
parsed_url = ParseResult( | ||
scheme="", netloc="", path=path, params="", query="", fragment="" | ||
) |
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.
Shouldn't we validate that path
comes in the exact shape we require here?
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.
Not sure if I understand what you mean with shape, anything can be a path, this is the path as we receive it from proxito.
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.
We are expecting a string with a particular structure. For example, it can't be https://humitos.dev/page/
, it has to be just /page/
. I'm saying that we should validate the path
to be what we expect to be instead of a random string.
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.
what we expect is a random string
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.
In the code comment you said that it should not start with a protocol, tho. I'm confused what are the correct values for path
then. Can you expand on this?
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.
The comment says we can't use unparse()
because the path could start with a protocol, or anything really that can confuse unparse()
so we manually build the ParseResult
class.
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.
Yeah, I got that. I'm not saying we have to use unparse()
. I'm saying that we can validate the string to be exactly in the shape we need to be and raise an exception otherwise.
:returns: None or a tuple with the current project, version and file. | ||
A tuple with only the project means we weren't able to find a version, | ||
but the translation was correct. | ||
:returns: A tuple with the current project, version and file. |
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.
Shouldn't this be an object? Maybe an Unresolved<Something>
object to keep consistency with the other objects.
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.
This is for internal usage only, they are always present.
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.
That's fine. Even if it's internal. Using well-known objects makes the code easier to read and follow.
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.
This 3 tuple elements is well-defined, I'd avoid creating data classes for every return type, if we have more than 3 things to return, then that would make sense for me.
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.
This is pretty close. I made some code suggestions to make it more clear and easy to follow/read without having all the context in mind.
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.
Thanks for taking my suggestions into consideration 👍🏼 . I'm fine moving forward with this PR.
Instead of returning a partial response, I'm just raising an exception with the information from the context where it happened, this will be used in proxito to decide what to do (redirect, raise 404, etc)