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

Fix bug in nb_lookup if api_filter contains multiple id #1042

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

linkdd
Copy link
Contributor

@linkdd linkdd commented Jul 28, 2023

Related Issue

New Behavior

In the nb_lookup plugin, when supplying multiple id fields to the api_filter parameter, it will return a list of items.

Contrast to Current Behavior

In the nb_lookup plugin, if we provide an api_filter containing the id field, it will use .get() instead of .filter(), thus returning the item instead of a list. See PR #376 for more information.

This is fine if you supply only one id. But let's say you want to get a list of items by ids?

For example: id=1 id=5

I would expect to get a list of 2 items. But at the moment, it will return the first item only.

This change adds a simple check to see if we're supplying multiple ids.

Discussion: Benefits and Drawbacks

This fixes a bug where supplying multiple ids in the api_filter ends up returning only one item.

In fact, I'd even expect that supplying a single id would return a list of one item, since we're querying a collection. So maybe a many=True|False parameter would be better?

This bugfix as it is is backward-compatible.

Double Check

  • I have read the comments and followed the CONTRIBUTING.md.
  • I have explained my PR according to the information in the comments or in a linked issue.
  • My PR targets the devel branch.

In the `nb_lookup` plugin, if we provide an `api_filter` containing the `id` field, it will use `.get()` instead of `.filter()`, thus returning the item instead of a list. See PR netbox-community#376 for more information.

This is fine if you supply only one id. But let's say you want to get a list of items by ids?

For example: `id=1 id=5`

I would expect to get a list of 2 items. But at the moment, it will return the first item only.

This change adds a simple check to see if we're supplying multiple ids.
@sc68cal
Copy link
Contributor

sc68cal commented Aug 1, 2023

At the very least, this needs a test that exercises sending two IDs as a filter and verifying the desired behavior

Copy link
Contributor

@sc68cal sc68cal left a comment

Choose a reason for hiding this comment

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

missing new integration test in https://github.com/netbox-community/ansible_modules/blob/devel/tests/integration/targets/v3.5/tasks/netbox_lookup.yml

make sure you add it to all the targets that we track

@rodvand rodvand merged commit 8cb1149 into netbox-community:devel Dec 10, 2023
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.

3 participants