-
Notifications
You must be signed in to change notification settings - Fork 93
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
SONARPY-2324 Document missing Django views due to missing resolution of self members #2148
Conversation
5a384c2
to
bca5c0c
Compare
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!
I'll put it back in progress because I left few minor comments on naming.
from django.urls import path | ||
|
||
class SameClassView: | ||
def chosen_view(self): # FN SONARPY-2322 | ||
... | ||
|
||
def get_urlpatterns(self): | ||
return [path("something", self.chosen_view, name="something")] |
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.
minor for clarity, I would put this test in another file called views_as_class_member
or views_as_class_method
, or something similar
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 makes sense! I added views_and_urls_same_file
to also cover a basic case of view defined in the same file as a url.
|
||
from django.urls import path | ||
|
||
class SameClassView: |
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.
nit I'm not sure SameClassView
is crystal clear.
class SameClassView: | |
class ClassWithViews: |
or something similar
from django.urls import path | ||
|
||
class SameClassView: | ||
def chosen_view(self): # FN SONARPY-2322 |
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.
def chosen_view(self): # FN SONARPY-2322 | |
def view_method(self): # FN SONARPY-2322 |
class SameClassView: | ||
def chosen_view(self): # FN SONARPY-2322 | ||
... | ||
|
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.
extra mile to get even closer to the original issue from our analysis, I would add a method using a property decorator :
@property
def view_property(self):
and ensure that we have also the FN.
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 rule already tests for various decorators. I deliberately removed the @property
one so that it doesn't bring confusion as to the root cause of the FN.
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.
ok makes sense !
class SameClassView: | ||
def chosen_view(self): |
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.
class SameClassView: | |
def chosen_view(self): | |
class ClassWithViews: | |
def view_method(self): |
ProjectLevelSymbolTable projectSymbolTable = new ProjectLevelSymbolTable(); | ||
projectSymbolTable.addModule(parseWithoutSymbols(content), "my_package", pythonFile("mod.py")); | ||
// SONARPY-2322: should be true | ||
assertThat(projectSymbolTable.isDjangoView("my_package.mod.SameClassView.chosen_view")).isFalse(); |
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 ran this test on commit d955f10, before the merge of MMF-3945, and I confirm that this assertion failed, i.e. chosen_view
is a Django view on this old commit.
bca5c0c
to
b74aaac
Compare
b74aaac
to
458246b
Compare
Quality Gate passedIssues Measures |
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 the renaming 💪
SONARPY-2324