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

Use Fields __all__ #70

Merged
merged 2 commits into from
Feb 6, 2024
Merged

Use Fields __all__ #70

merged 2 commits into from
Feb 6, 2024

Conversation

snaselj
Copy link
Contributor

@snaselj snaselj commented Jan 19, 2024

Closes NaN

What's Changed

  • Added nb-use-fields-all checker.

To Do

  • Merge Standardize #71 first.
  • Add more metaclasses to be checked.
  • Pass fields node value as a failing node.

@itdependsnetworks
Copy link

Thanks for doing this, happy to see this!!

)


class NautobotUseFieldsAll(BaseChecker):

Choose a reason for hiding this comment

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

Just making sure that we are purposeful, do we want to:

  • Create one check for all types (serializer, forms, tables, etc)
  • Create one check for each type, using mostly the same code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@whitej6 WDYT?

Copy link

Choose a reason for hiding this comment

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

I am 50/50 on this. I see the benefit to have essentially N subclasses with an abstracted method on checking ancestor BUT that adds repetitive code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just agreed to go with single checker for all types.

_META_CLASSES = (
"nautobot.utilities.tables.BaseTable.Meta",
# TBD: Add support for other Meta classes
"nautobot.extras.forms.NautobotModelForm.Meta",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@whitej6

Could you please help me identify all classes that should be checked?

Choose a reason for hiding this comment

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

This is the list / thoughts I cam up with:

  • NautobotModelSerializer - Yes
  • NautobotModelForm - Yes
  • NautobotFilterSet - Capability should be added, but does not exist today
  • NautobotBulkEditForm - Unclear, in floor app I see it defined, but others I do not, perhaps it is an implied all, in which case I think better to be explicit and convert to respect the all param as best practices)
  • NautobotFilterForm - Not needed (can investigate other options for field_order)
  • BaseTable - Worth investigation what can be done, but does not exist today and may not be applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to _META_CLASSES.

@snaselj snaselj requested a review from whitej6 January 19, 2024 15:11
@snaselj snaselj force-pushed the u/snaselj-napps-184-use-all branch 2 times, most recently from 70c9756 to aa9796f Compare January 26, 2024 13:16
@snaselj snaselj marked this pull request as ready for review January 29, 2024 12:16
@snaselj snaselj requested review from cmsirbu, Kircheneer and a team as code owners January 29, 2024 12:16
@snaselj
Copy link
Contributor Author

snaselj commented Jan 29, 2024

This PR is ready for review @whitej6 @cmsirbu @Kircheneer

@snaselj
Copy link
Contributor Author

snaselj commented Jan 29, 2024

Adding a screenshot of failing rule.

screenshot

Comment on lines 16 to 17
# NautobotBulkEditForm - Unclear, in floor app I see it defined, but others I do not, perhaps it is an implied all, in which case I think better to be explicit and convert to respect the all param as best practices)
# NautobotFilterForm - Not needed (can investigate other options for field_order)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps better to move the uncertain ones to a new issue and discuss there what else could be added?

Copy link

Choose a reason for hiding this comment

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

FilterForm requires a change upstream before it can be added for __all__

BulkEditForm I do not believe this is applicable since this does not have an ancestor of django.forms.ModelForm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments are removed.

@snaselj
Copy link
Contributor Author

snaselj commented Feb 6, 2024

All comments has been addressed, 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, thanks!

@cmsirbu cmsirbu merged commit 56cc6bb into develop Feb 6, 2024
15 checks passed
@cmsirbu cmsirbu deleted the u/snaselj-napps-184-use-all branch February 6, 2024 16:02
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