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

Unable to filter ip-addresses by assigned_object_type via REST API #17559

Closed
Konunacmep opened this issue Sep 20, 2024 · 6 comments
Closed

Unable to filter ip-addresses by assigned_object_type via REST API #17559

Konunacmep opened this issue Sep 20, 2024 · 6 comments
Labels
netbox type: bug A confirmed report of unexpected behavior in the application

Comments

@Konunacmep
Copy link

Konunacmep commented Sep 20, 2024

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.11

Steps to Reproduce

Сan be reproduced on the demo.

  1. Log in to https://demo.netbox.dev
  2. Request any of:

Expected Behavior

Expecting response with filtered list of ip-addresses with specified assigned_object_type (as it was on version 3)

Observed Behavior

Regardless of the parameter value (dcim.interface/virtualization.vminterface/ipam.fhrpgroup) get a response:
"assigned_object_type": [
"Select a valid choice. That choice is not one of the available choices."
]
From the docs: "assigned_object_type - The content type of the assigned object, defined as <app>.<model>".

It is noticed that the parameter accepts numeric values ​​of identifiers from api/extras/object-types for GET requests and filtering works. However, for POST it responds with "'assigned_object_type': ["Invalid value. Specify a content type as '<app_label>.<model_name>'."]" and working with values defined as <app>.<model>.

Initially the problem was noticed after the update from 3.7.1 to 4.0.8, however, the behavior is the same on a clean installation of 4.1.1.

@Konunacmep Konunacmep added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Sep 20, 2024
@arthanson arthanson self-assigned this Oct 4, 2024
@arthanson arthanson added status: revisions needed This issue requires additional information to be actionable and removed status: needs triage This issue is awaiting triage by a maintainer labels Oct 4, 2024
@arthanson
Copy link
Collaborator

@Konunacmep which previous version of NetBox were you seeing this working in? I tried with v3.7 and it is not returning the interfaces using this query (see screenshot).
IP Address | NetBox REST API 2024-10-04 08-20-22

@Konunacmep
Copy link
Author

Hi @arthanson, just checked, yes you are right. On 3.7.1, filtering by assigned_object_type does not return an error, but passes unfiltered values ​​into the result. In my opinion, this is also incorrect behavior, because to search by a assigned object, filtering must be performed by a set of assigned_object_type and assigned_object_id fields (polymorphic relationship), assigned_object_id alone is not enough.
Based on this, filtering by the specified field did not work on the 3rd version, but starting with version 4, a problem with the format of the received values ​​appeared.
I apologize for not correctly indicating the version in which the problem appeared.
This does not cancel the impossibility of filtering by the assigned_object_type field declared in this case.
This functionality is necessary to search for IP addresses assigned to an interface, if it is possible to obtain this data in another way, please indicate.

Copy link
Contributor

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Oct 15, 2024
@Konunacmep
Copy link
Author

Please do not close the case, as we are already talking about 2 unclosed bugs in the REST API ipam.ipaddresses:

  • non-working filtering by the assigned_object_type field since 3.7 or earlier
  • a problem with the accepted format and type of values ​​for the assigned_object_type field in GET requests that appeared since version 4

@arthanson arthanson removed their assignment Oct 15, 2024
@jeremystretch
Copy link
Member

IP addresses can filter be filtered by specifying the numeric ID of the assigned content type, e.g. ?assigned_object_type=39. While this is inconsistent with filters which take the content type name rather than the ID, the functionality does exist. Any changes to this filter would require a feature request as it would break the existing behavior.

@jeremystretch jeremystretch closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
@jeremystretch jeremystretch removed status: revisions needed This issue requires additional information to be actionable pending closure Requires immediate attention to avoid being closed for inactivity labels Oct 22, 2024
@Konunacmep
Copy link
Author

Thanks for the answer. This is the "workaround" I am currently using to get around the problem. Although, as we found out in this case, this filter does not work at all.

In my opinion, this is definitely a bug that appeared after the update from version 3 to 4. In GET requests, you will have to pass numeric ids, and in POST - strings, in responses also string type. The field should both accept and return the string type, as it was in version 3 and it described in the documentation: https://demo.netbox.dev/static/docs/rest-api/overview/#generic-relations.
I also can't call non-working filtering by key field normal.
But the developers know better.
If fixes are not planned, then the case can be closed, I don't see the point in further discussion.

I would like to note for those who encountered this bug that when using numeric values ​​of assigned_object_type id, these id's can be unique for each specific Netbox instance. The id values ​​of the current Netbox instance should be looked up in /api/extras/object-types/

@jeremystretch jeremystretch added the netbox label Nov 1, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
netbox type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants