-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
fix: check type of url before performing string actions #19569
Conversation
e85dcb6
to
117d113
Compare
Codecov Report
@@ Coverage Diff @@
## master #19569 +/- ##
===========================================
- Coverage 66.65% 53.94% -12.72%
===========================================
Files 1680 1680
Lines 64271 64274 +3
Branches 6564 6564
===========================================
- Hits 42842 34673 -8169
- Misses 19727 27899 +8172
Partials 1702 1702
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
superset/databases/utils.py
Outdated
@@ -112,7 +112,9 @@ def make_url_safe(raw_url: str) -> URL: | |||
:param raw_url: | |||
:return: | |||
""" | |||
|
|||
url = str(raw_url).strip() |
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.
if url
might not be a string, can you fix the typing of the function?
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, that's tricky. I found that sometimes we're passing in Url
because this method has already previously been run on a uri before it was passed in here, but it would technically be better if this function were passed in a string. But since the typing is just a hint, we still need to provide our own guards against incorrect types. Do you think adding Url
to the typing is still helpful or maybe a comment 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.
Actually now that I look at the function parameter types for the original make_url, it can take a URL and then just returns the same URL. Good call. I think I'll do the same 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.
Thanks for making the change. We definitely want the type hints to match the actual types passed in. mypy should ideally catch this when type checking too, i'm wondering why that wasn't the case
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.
lgtm, thanks for adding tests too!
a7ad6e2
to
79c76c9
Compare
* ensure url is a string * return url if param is a url (cherry picked from commit aa419b8)
* ensure url is a string * return url if param is a url (cherry picked from commit aa419b8)
* ensure url is a string * return url if param is a url (cherry picked from commit aa419b8)
🏷️ preset:2022.11 |
* ensure url is a string * return url if param is a url
SUMMARY
This small change ensures that a uri is a string before performing the
strip
method on it. If the param is aURL
, like the original function, it will just return the value.TESTING INSTRUCTIONS
automated tests to check that the make_url_safe function can take both a string or a
Url
ADDITIONAL INFORMATION