Export and Import Custom Fields #5630

Closed
opened 2025-12-29 19:30:18 +01:00 by adam · 8 comments
Owner

Originally created by @dmetzler1988 on GitHub (Nov 8, 2021).

NetBox version

v3.0.9

Python version

3.9

Steps to Reproduce

  1. Create new custom fields with choices (no one exists previously)
  2. Export these custom fields via button Export -> All data
  3. Remove the created custom fields
  4. Import this exported CSV via CSV File Upload
    4.1 An error would occur, that the ID in the first line is not expected.
  5. Open the exported CSV in a text-editor, remove ID in header and on the lines
    5.1 Modify title names to these which are given/listed on import page (all to lowercase, replace spaces with underscore)
    # from
    ID,Name,Content types,Label,Type,Required,Weight,Default,Description,Filter logic,Choices
    # to
    name,content_types,label,type,required,weight,default,description,filter_logic,choices
    
  6. Import this via CSV Data input field and click on Submit

Expected Behavior

The Custom fields will be imported without an error - in an optimal world without a need to modify the exported data.

Observed Behavior

On step 4 this error occurs (as a red popup):

Unexpected column header "ID" found.

If we only remove the ID in header and body, this error occurs at next (as a red popup)

Unexpected column header "Name" found.

And so on for each header column name from export.


On step 6 this error occurs via new Server Errorpage:

<class 'ValueError'>

not enough values to unpack (expected 2, got 1)

Python version: 3.9.5
NetBox version: 3.0.9
Originally created by @dmetzler1988 on GitHub (Nov 8, 2021). ### NetBox version v3.0.9 ### Python version 3.9 ### Steps to Reproduce 1. Create new custom fields with choices (no one exists previously) 2. Export these custom fields via button `Export` -> `All data` 3. Remove the created custom fields 4. Import this exported CSV via `CSV File Upload` 4.1 An error would occur, that the ID in the first line is not expected. 5. Open the exported CSV in a text-editor, remove ID in header and on the lines 5.1 Modify title names to these which are given/listed on import page (all to lowercase, replace spaces with underscore) ``` # from ID,Name,Content types,Label,Type,Required,Weight,Default,Description,Filter logic,Choices # to name,content_types,label,type,required,weight,default,description,filter_logic,choices ```` 6. Import this via `CSV Data` input field and click on `Submit` ### Expected Behavior The Custom fields will be imported without an error - in an optimal world without a need to modify the exported data. ### Observed Behavior On step 4 this error occurs (as a red popup): ``` Unexpected column header "ID" found. ``` If we only remove the ID in header and body, this error occurs at next (as a red popup) ``` Unexpected column header "Name" found. ``` And so on for each header column name from export. --- On step 6 this error occurs via new `Server Error`page: ``` <class 'ValueError'> not enough values to unpack (expected 2, got 1) Python version: 3.9.5 NetBox version: 3.0.9 ```
adam added the type: bug label 2025-12-29 19:30:18 +01:00
adam closed this issue 2025-12-29 19:30:18 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 8, 2021):

  1. Modify title names to these which are given/listed on import page (all to lowercase, replace spaces with underscore)

I'm afraid this is not sufficient detail for a bug report. Please update your post above to include the exact data being used to reproduce the bug.

@jeremystretch commented on GitHub (Nov 8, 2021): > 5. Modify title names to these which are given/listed on import page (all to lowercase, replace spaces with underscore) I'm afraid this is not sufficient detail for a bug report. Please update your post above to include the exact data being used to reproduce the bug.
Author
Owner

@dmetzler1988 commented on GitHub (Nov 8, 2021):

ok, added some testdata.

Exported file from Netbox
netbox_custom fields.csv

Modified header column for manual import via input field - content is the same than from export - without ID on first position

name,content_types,label,type,required,weight,default,description,filter_logic,choices
test1,"IPAM &gt; IP address, IPAM &gt; prefix, IPAM &gt; VRF",Test One,Text,True,100,,,Loose,[]
test_two,"DCIM &gt; device, IPAM &gt; IP address, IPAM &gt; prefix, IPAM &gt; VRF",Test Two,Selection,True,100,,,Loose,"['choice1', 'choice2', 'third choice', 'last choice']"

edit

i can also reproduce this case on https://demo.netbox.dev
tried it there with a simple import:

name,content_types,label,type,required,weight,default,description,filter_logic,choices
cust_id,Tenancy &gt; tenant,Customer ID,Text,False,100,,,Exact,[]
@dmetzler1988 commented on GitHub (Nov 8, 2021): ok, added some testdata. **Exported file from Netbox** [netbox_custom fields.csv](https://github.com/netbox-community/netbox/files/7497157/netbox_custom.fields.csv) **Modified header column for manual import via input field - content is the same than from export - without ID on first position** ``` name,content_types,label,type,required,weight,default,description,filter_logic,choices test1,"IPAM &gt; IP address, IPAM &gt; prefix, IPAM &gt; VRF",Test One,Text,True,100,,,Loose,[] test_two,"DCIM &gt; device, IPAM &gt; IP address, IPAM &gt; prefix, IPAM &gt; VRF",Test Two,Selection,True,100,,,Loose,"['choice1', 'choice2', 'third choice', 'last choice']" ``` --- *edit* i can also reproduce this case on https://demo.netbox.dev tried it there with a simple import: ``` name,content_types,label,type,required,weight,default,description,filter_logic,choices cust_id,Tenancy &gt; tenant,Customer ID,Text,False,100,,,Exact,[] ```
Author
Owner

@jeremystretch commented on GitHub (Nov 9, 2021):

The values you've provided for the content types are invalid. The export format uses human-friendly names (e.g. "DCIM > Site"), whereas the import format expects the "dotted" notation (e.g. dcim.site).

@jeremystretch commented on GitHub (Nov 9, 2021): The values you've provided for the content types are invalid. The export format uses human-friendly names (e.g. "DCIM > Site"), whereas the import format expects the "dotted" notation (e.g. `dcim.site`).
Author
Owner

@dmetzler1988 commented on GitHub (Nov 10, 2021):

Ok, that means we need to modify the complete export from System A if we would like to import on System B. This would therefore mean a huge effort for such a simple usecase.

But if that's the way it's planned, so be it.

Do you have a reference-docu for the import style, so that we can check the differences?
Do you maybe have another solution, to export custom-fields from system A to system B (without datas or anything else)?

@dmetzler1988 commented on GitHub (Nov 10, 2021): Ok, that means we need to modify the complete export from System A if we would like to import on System B. This would therefore mean a huge effort for such a simple usecase. But if that's the way it's planned, so be it. Do you have a reference-docu for the import style, so that we can check the differences? Do you maybe have another solution, to export custom-fields from system A to system B (without datas or anything else)?
Author
Owner

@jeremystretch commented on GitHub (Nov 10, 2021):

Do you have a reference-docu for the import style, so that we can check the differences?

There's a complete reference right on the import page.

Do you maybe have another solution, to export custom-fields from system A to system B (without datas or anything else)?

You can very easily craft a custom export template to export custom fields in whatever format you'd like.

@jeremystretch commented on GitHub (Nov 10, 2021): > Do you have a reference-docu for the import style, so that we can check the differences? There's a complete reference right on the import page. > Do you maybe have another solution, to export custom-fields from system A to system B (without datas or anything else)? You can very easily craft a [custom export template](https://netbox.readthedocs.io/en/stable/customization/export-templates/) to export custom fields in whatever format you'd like.
Author
Owner

@dmetzler1988 commented on GitHub (Nov 10, 2021):

There's a complete reference right on the import page.

Yes, but the information for dot-notation is missing - i only see a info-popup with numbers as reference for the paths - like 73 for tenancy | tenant. But the numbers also won't work for imports.

You can very easily craft a custom export template to export custom fields in whatever format you'd like.

But this expect to be a template for a page to export datas - not the custom fields settings. I can't choose extras/custom-fields as content-type for the custom export template.
Maybe my definition was not clear enough or we may have a misunderstanding - i would like to export the custom fields settings on /extras/custom-fields, not the content in the custom fields.

@dmetzler1988 commented on GitHub (Nov 10, 2021): > There's a complete reference right on the import page. Yes, but the information for dot-notation is missing - i only see a info-popup with numbers as reference for the paths - like `73` for `tenancy | tenant`. But the numbers also won't work for imports. > You can very easily craft a custom export template to export custom fields in whatever format you'd like. But this expect to be a template for a page to export datas - not the custom fields settings. I can't choose `extras/custom-fields` as `content-type` for the custom export template. Maybe my definition was not clear enough or we may have a misunderstanding - i would like to export the custom fields settings on `/extras/custom-fields`, not the content in the custom fields.
Author
Owner

@jeremystretch commented on GitHub (Nov 11, 2021):

Yes, but the information for dot-notation is missing - i only see a info-popup with numbers as reference for the paths - like 73 for tenancy | tenant.

Ok, that's a bug. It should be listing the dotted formats for these choices. I've opened #7808.

I can't choose extras/custom-fields as content-type for the custom export template.

Looks like that's actually another bug. Looks like we missed adding export template support when custom fields (and other models) were moved from the admin UI to the main UI in v3.0. I've opened #7809 for this one.

Separate from the bugs above, I suppose what we could do is just change the "DCIM > Site" format to "dcim.site". It's not quite as clean, but having one consistent expression for each content type probably yields a better return.

@jeremystretch commented on GitHub (Nov 11, 2021): > Yes, but the information for dot-notation is missing - i only see a info-popup with numbers as reference for the paths - like 73 for tenancy | tenant. Ok, that's a bug. It should be listing the dotted formats for these choices. I've opened #7808. > I can't choose extras/custom-fields as content-type for the custom export template. Looks like that's actually another bug. Looks like we missed adding export template support when custom fields (and other models) were moved from the admin UI to the main UI in v3.0. I've opened #7809 for this one. Separate from the bugs above, I suppose what we could do is just change the "DCIM > Site" format to "dcim.site". It's not quite as clean, but having one consistent expression for each content type probably yields a better return.
Author
Owner

@jeremystretch commented on GitHub (Nov 17, 2021):

I suppose what we could do is just change the "DCIM > Site" format to "dcim.site".

I've opened #7858 to address this application-wide.

@jeremystretch commented on GitHub (Nov 17, 2021): > I suppose what we could do is just change the "DCIM > Site" format to "dcim.site". I've opened #7858 to address this application-wide.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5630