-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
#5791: Address errors found by lgtm.com #7403
#5791: Address errors found by lgtm.com #7403
Conversation
0ab7e72
to
a3eada7
Compare
Codecov Report
@@ Coverage Diff @@
## master #7403 +/- ##
==========================================
+ Coverage 65.71% 65.74% +0.02%
==========================================
Files 459 459
Lines 21983 21980 -3
Branches 2415 2413 -2
==========================================
+ Hits 14446 14450 +4
+ Misses 7416 7410 -6
+ Partials 121 120 -1
Continue to review full report at Codecov.
|
3146e1d
to
7bb26da
Compare
superset/connectors/druid/models.py
Outdated
@@ -83,6 +84,8 @@ def __init__(self, name, field_names, function): | |||
class CustomPostAggregator(Postaggregator): | |||
"""A way to allow users to specify completely custom PostAggregators""" | |||
def __init__(self, name, post_aggregator): | |||
# TODO(gianluca): Is this the right way? should I use the arg post_aggregator? | |||
Postaggregator.__init__(self, None, None, name) |
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.
Please use super
instead.
superset/stats_logger.py
Outdated
@@ -82,6 +82,7 @@ def __init__(self, host='localhost', port=8125, | |||
If statsd_client argument is given, all other arguments are ignored and the | |||
supplied client will be used to emit metrics. | |||
""" | |||
BaseStatsLogger.__init__(self, prefix) |
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.
Please use super
instead.
superset/utils/core.py
Outdated
def __get__(self, obj, objtype): | ||
if not self.is_method: | ||
self.is_method = True | ||
copy = self.__copy__() | ||
return functools.partial(copy.__call__, obj) |
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.
Could you provide some more context as to what you’re trying to achieve 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.
The analyzer at lgtm.com finds this assignment harmful (https://lgtm.com/rules/910074/).
The problem is (AFAIU) that we are mutating a descriptor object, and this can cause surprises to different instances of the same class. The recommendation is to create a copy that contains the desired state and return that instead.
In a patch I haven't pushed yet, I do a copy.is_method = True
before returning as I do here. I wanted to copy the present instance, mutate it, and return it.
This, however, makes the unit tests test_memoized_on_methods_with_watches
and test_memoized_on_methods
fail.
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.
On further thought, I think that the code uses this pattern to actually achieve the desired result. What I propose, in this case, is to either silence the alert with # lgtm[py/mutable-descriptor]
, or to just ignore it. Maybe a comment in the code would be enough?
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.
@john-bodley kindly when you find a minute can you advise on this?
tests/access_tests.py
Outdated
@@ -428,6 +428,14 @@ def test_approve(self, mock_send_mime): | |||
session.delete(security_manager.find_role(TEST_ROLE_NAME)) | |||
session.commit() | |||
|
|||
def test_dashboard_endpoint_malicious_redirect(self): | |||
# todo(gianluca.ciccarelli@bolt.eu): I need a dashboard ID that will |
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.
You could try using -1
(though I’m unsure if that works), otherwise maybe querying for the maximum dashboard ID and adding one, or using 9999
.
superset/connectors/druid/models.py
Outdated
@@ -71,6 +71,7 @@ def _fetch_metadata_for(datasource): | |||
|
|||
class JavascriptPostAggregator(Postaggregator): | |||
def __init__(self, name, field_names, function): | |||
Postaggregator.__init__(self, function, field_names, name) |
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.
Edits to this file seems unrelated to your PR title
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 agree. The thing is that I started on the issue but gave a title related to the first I had started tackling. Do you suggest changing the title or split the PR into a few ones? (I'd favor the first.)
7bb26da
to
03ff19c
Compare
93cfe38
to
e9c0a75
Compare
@mistercrunch @john-bodley please when you have time can you have a look at this? In the meanwhile, I'll start addressing the lower-priority alerts (I remember seeing many unused imports, they should be safe to remove). |
To be clear, I think this patch could be merged as-is, but I'll add some lower-priority work to it that won't hurt. At least that's the plan 😄 |
e71dcf4
to
e96416c
Compare
82df7c7
to
28acf04
Compare
I need to re-scope this one in light of the more recent alerts. I think that the important is that I manage to fix the 4 errors currently pointed out. |
Now it should fix the 4 Errors and tackle a few Warnings as a bonus. It would be useful to point LGTM.com to this branch and check that that is actually the case, but I haven't been able to. Is there still interest in going through with this? @john-bodley @mistercrunch |
cd59f46
to
2b0d317
Compare
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue |
CATEGORY
Choose one
SUMMARY
The website LGTM.com has detected a few errors from static analysis. This patch contains a possible fix for the first of them ("URL redirection from remote source") that follows the website's own recommendation: Check the input against some known source before using it. I've checked that the dashboard ID provided actually exists in DB and if it doesn't I return a 404.
I plan to solve the other 4 issues labeled as "Error" but wanted to get some early feedback before moving on.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable.
TEST PLAN
I've written a unit test that can be run e.g. like:
tox -e py37 -- tests/access_tests.py:RequestAccessTests.test_dashboard_endpoint_malicious_redirect
ADDITIONAL INFORMATION
REVIEWERS
Please @mistercrunch as original reporter but feel free to re-assign as you see fit.