Skip to content
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

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

guillaume-dequenne-sonarsource
Copy link
Contributor

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource commented Nov 12, 2024

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource marked this pull request as ready for review November 12, 2024 10:47
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Document missing Django views due to missing resolution of self members SONARPY-2324 Document missing Django views due to missing resolution of self members Nov 12, 2024
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the document-s3752-fn branch 3 times, most recently from 5a384c2 to bca5c0c Compare November 12, 2024 13:33
Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a 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.

Comment on lines 54 to 61
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")]
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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.

Suggested change
class SameClassView:
class ClassWithViews:

or something similar

from django.urls import path

class SameClassView:
def chosen_view(self): # FN SONARPY-2322
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def chosen_view(self): # FN SONARPY-2322
def view_method(self): # FN SONARPY-2322

class SameClassView:
def chosen_view(self): # FN SONARPY-2322
...

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok makes sense !

Comment on lines 1059 to 1060
class SameClassView:
def chosen_view(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
Copy link
Contributor

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.

Copy link

Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a 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 💪

@thomas-serre-sonarsource thomas-serre-sonarsource merged commit 74f8f65 into master Nov 15, 2024
14 checks passed
@thomas-serre-sonarsource thomas-serre-sonarsource deleted the document-s3752-fn branch November 15, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants