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

Improve incorrect base class checker #72

Merged
merged 5 commits into from
Feb 14, 2024

Conversation

snaselj
Copy link
Contributor

@snaselj snaselj commented Jan 29, 2024

Closes NaN

What's Changed

  • ModelForm to incorrect classes checker.
  • Added version constraints to each incorrect class checker mapping.
  • Added tests for all checked classes.

@snaselj snaselj marked this pull request as ready for review January 29, 2024 13:11
@snaselj snaselj requested review from cmsirbu, Kircheneer and a team as code owners January 29, 2024 13:11
_CLASS_MAPPING = (
{
"incorrect": "django_filters.filters.FilterSet",
"correct": "django_filters.filters.BaseFilterSet",
Copy link

Choose a reason for hiding this comment

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

Suggested change
"correct": "django_filters.filters.BaseFilterSet",
"correct": "nautobot.apps.filters.NautobotFilterSet",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

},
{
"incorrect": "django.db.models.base.Model",
"correct": "nautobot.core.models.BaseModel",
Copy link

Choose a reason for hiding this comment

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

Not sure if we support OR but Primary should always be the preferred and base is only used for custom through tables and a few other scenarios.

Suggested change
"correct": "nautobot.core.models.BaseModel",
"correct": ["nautobot.apps.models.PrimaryModel","nautobot.apps.models.BaseModel"]

Copy link
Contributor Author

@snaselj snaselj Feb 12, 2024

Choose a reason for hiding this comment

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

PrimaryModel is a BaseModel descendant. If we want to allow BaseModel to be used, it covers PrimaryModel as well.

One simple option is to enforce PrimaryModel, instead of BaseModel. In such case, using BaseModel only would have to be disabled by # pylint: disable=nb-incorrect-base-class macro.

Copy link

Choose a reason for hiding this comment

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

I vote enforce PrimaryModel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PrimaryModel is enforced now.

@snaselj
Copy link
Contributor Author

snaselj commented Feb 12, 2024

All comments has been addressed, this pull request is ready for review.

Copy link
Collaborator

@cmsirbu cmsirbu left a comment

Choose a reason for hiding this comment

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

LGTM

@cmsirbu cmsirbu merged commit 574fe3e into develop Feb 14, 2024
15 checks passed
@cmsirbu cmsirbu deleted the u/snaselj-incorrect-base-class branch February 14, 2024 15:20
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.

4 participants