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

Django models __str__ codemod #302

Merged
merged 8 commits into from
Feb 28, 2024
Merged

Django models __str__ codemod #302

merged 8 commits into from
Feb 28, 2024

Conversation

clavedeluna
Copy link
Contributor

@clavedeluna clavedeluna commented Feb 25, 2024

Overview

Codemod that will add a cookie-cutter __str__ method to any django model class that did not implement it

Description

  • The implement

Additional Details

  • Found this django app plugin during my research https://pypi.org/project/django-dunder/#history
  • There is a corresponding sonar rule for this but I wasn't able to get sonarcloud to fire so this will be investigated later on in a separate issue. Please ignore early sonarcloud failures as I was testing that part out.

Closes #287

)


parser = etree.XMLParser() # Noncompliant

Check failure

Code scanning / SonarCloud

XML parsers should not be vulnerable to XXE attacks

<!--SONAR_ISSUE_KEY:AY3hpmw2qlbWBFrI689Y-->Disable access to external entities in XML parsing. <p>See more on <a href="https://sonarcloud.io/project/issues?id=pixee_codemodder-python&issues=AY3hpmw2qlbWBFrI689Y&open=AY3hpmw2qlbWBFrI689Y&pullRequest=302">SonarCloud</a></p>
@clavedeluna clavedeluna force-pushed the django-str branch 3 times, most recently from ce33072 to b1d623f Compare February 27, 2024 11:29
@clavedeluna clavedeluna marked this pull request as ready for review February 27, 2024 11:40
Copy link
Contributor

@andrecsilva andrecsilva left a comment

Choose a reason for hiding this comment

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

Minor change

Copy link
Member

@drdavella drdavella left a comment

Choose a reason for hiding this comment

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

Looks really nice overall. Just some requests for updating metadata and then we should be good.


DjangoModelWithoutDunderStr = CoreCodemod(
metadata=Metadata(
name="django-model-without-dunder-str",
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge deal but I feel like we're sometimes inconsistent as to whether a codemod is phrased in terms of a problem or a fix. I think we should prefer names in terms of fixes add-django-model-dunder-str but maybe we can just take it as a suggestion going forward.

src/core_codemods/django_model_without_dunder_str.py Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Feb 28, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@clavedeluna clavedeluna added this pull request to the merge queue Feb 28, 2024
Merged via the queue into main with commit 7075794 Feb 28, 2024
11 checks passed
@clavedeluna clavedeluna deleted the django-str branch February 28, 2024 16:34
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.

Codemod to add a __str__ method to a Django model that didn't define it
3 participants