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 create custom field of type object or multiobject via API #8976

Closed
squintfox opened this issue Mar 26, 2022 · 2 comments
Closed

Unable to create custom field of type object or multiobject via API #8976

squintfox opened this issue Mar 26, 2022 · 2 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@squintfox
Copy link

NetBox version

v3.2-beta2

Python version

3.9

Steps to Reproduce

  1. POST the following to: https:///api/extras/custom-fields/
    {
    "content_types": [
    "ipam.prefix"
    ],
    "type": "object",
    "data_type": "object",
    "object_type": "circuits.circuit",
    "name": "circuit",
    "label": "Circuit"
    }

Expected Behavior

A new custom field should be created.

Observed Behavior

The API returns:
{
"object_type": [
"Object fields must define an object type."
]
}

It does not matter what value you supply for object_type or if you don't specify one at all.

@squintfox squintfox added the type: bug A confirmed report of unexpected behavior in the application label Mar 26, 2022
@squintfox
Copy link
Author

I believe (at least in part) the issue is the the field object_type is missing from CustomFieldSerializer in /netbox/netbox/extras/api/serializers.py. I modified this:

fields = [
'id', 'url', 'display', 'content_types', 'type', 'data_type', 'name', 'label', 'description', 'required',
'filter_logic', 'default', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
'object_type', 'choices', 'created', 'last_updated',
]

After I restarted netbox, object_type was now shown in API GET queries for custom fields (it was not previously) and I was able to create a custom field by supplying the int id of "circuits.circuit". Given what I've see of the API and how it handles linked objects, this doesn't seem like a complete solution, but hopefully this is helpful for someone who understands it better than I do.

@jeremystretch jeremystretch added beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation labels Mar 28, 2022
@jeremystretch jeremystretch self-assigned this Mar 28, 2022
@jeremystretch
Copy link
Member

@squintfox yep, that's pretty much it. In this case, we want to make object_type a ContentTypeField, so that it returns a human-friendly descriptor (e.g. "circuit.circuit") instead of the PK, adding the missing field was the key. Thanks for the report!

This was referenced Apr 5, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

2 participants