Skip to content

Filter arguments validation #695

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

Open
m0nkeyc0de opened this issue Jun 2, 2025 · 1 comment
Open

Filter arguments validation #695

m0nkeyc0de opened this issue Jun 2, 2025 · 1 comment
Assignees
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@m0nkeyc0de
Copy link

m0nkeyc0de commented Jun 2, 2025

pynetbox version

v7.5.0

NetBox version

v.4.3.1

Feature type

New functionality

Proposed functionality

Validation of the filter Endpoint arguments before sending request to NetBox, using the openapi description provided by NetBox itself, which is supposed to contain all the supported filter expressions.

A first version of this implementation is here : https://github.com/m0nkeyc0de/pynetbox/tree/filter-validation

  • Default behavior of pynetbox is conserved. The feature must be activated with the strict_filter kwarg.
  • The openapi method that fetches the API specification was already implemented. I modified it to avoid repeated calls for always the same data on the NetBox API.
  • The _validate_openapi_parameters which does the validation work is added in the Endpoint class and is called within the filter() method.

What could be improved:

  • Log warnings if strict_filter is not enabled
  • Handle eventual missing dict key in the openapi specifications nicely
  • Per-request enabling/disabling the strict filter mode
  • Proper documentation

Use case

As described in #693 the actual behavior of NetBox is to return the entire database table if an error is made in the filter. There is no indication that the API user made an error. You could get 4321 results because your filter matches all the objects but you also could get 4321 objects because you mistyped a filter without noticing it right away.

This would improve the quality of life for NetBox API users and reduce the risk of making invisible mistakes.

External dependencies

No additional external python dependencies are needed.

@m0nkeyc0de m0nkeyc0de added type: feature Introduction of new functionality to the application status: needs triage The issue is awaiting triage by a maintainer labels Jun 2, 2025
@m0nkeyc0de
Copy link
Author

You can assign the issue to me

@jnovinger jnovinger added status: accepted This issue has been accepted for implementation and removed status: needs triage The issue is awaiting triage by a maintainer labels Jun 6, 2025
@jnovinger jnovinger added the complexity: low Requires minimal effort to implement label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

2 participants