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

Error in export template silently causes the default export to be used instead #7813

Closed
candlerb opened this issue Nov 12, 2021 · 3 comments
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@candlerb
Copy link
Contributor

NetBox version

v3.0.9

Python version

3.8

Steps to Reproduce

Create a new export template:

  • Content Type: dcim | cable
  • Name: Cables for CSV re-import
  • Template as follows:
side_a_device,side_a_type,side_a_name,side_b_device,side_b_type,side_b_name,type,status,label,color,length,length_unit
{%- for c in queryset %}
{%- set lenitems = c.length.split(' ') %}
{{ c.termination_a.device.name }},
{{ c.termination_a_type.app_labeled_name }},{{ c.termination_a.name }},{{ c.termination_b.device.name }},
{{ c.termination_b_type.app_labeled_name }},{{ c.termination_b.name }},{{ c.type }},{{ c.status }},{{ c.label }},{{ lenitems[0] }},{{ lenitems[1] }}
{%- endfor %}

Now browse to cables, select a filter which limits them to a single device.

Click on Export > Cables for CSV Import

image

This links to dcim/cables/?q=&device_id=952&type=&status=&color=&export=Cables%20for%20CSV%20re-import

Expected Behavior

The downloaded CSV file would be formatted in accordance with the given template

OR: if the template is invalid, that an error would be reported.

Observed Behavior

The file netbox_cables.csv which is generated uses the default CSV formatting, ignoring the selected export template:

ID,Label,Side A,Termination A,Side B,Termination B,Status,Type,Length,Color,Tags
1791,,ldex-r17-sw1,PSU,PDU-R17-1,OUT24,Connected,Power,,,
1808,,ldex-r17-sw1,Gi1/0/24,mod-rj45-r17-r18-1-4,F1,Connected,CAT5e,50.00 Centimeters,#ffeb3b,
... etc
@candlerb candlerb added the type: bug A confirmed report of unexpected behavior in the application label Nov 12, 2021
@candlerb
Copy link
Contributor Author

If I change the template body to just

Hello World

then (1) the downloaded file is called netbox_cables instead of netbox_cables.csv, and (2) it has the selected content.

If I change the template body to

{%- for c in queryset %}
{{ c.id }}
{%- endfor %}

then netbox_cables contains a list of IDs. So I believe that I had some error in the original template, but this error was silently ignored and caused the default rendering to be used instead. If so, this isn't very helpful when trying to debug a template.

@candlerb candlerb changed the title CSV export template not being used Error in export template silently causes the default export to be used instead Nov 12, 2021
@candlerb
Copy link
Contributor Author

candlerb commented Nov 12, 2021

Definitely the export template was bad. FWIW here's the debugged version:

side_a_device,side_a_type,side_a_name,side_b_device,side_b_type,side_b_name,type,status,label,color,length,length_unit
{%- for c in queryset %}
{%- if c.termination_a_type.app_label != 'circuits' and c.termination_b_type.app_label != 'circuits' %}
{{ c.termination_a.device.name }},{{ c.termination_a_type.app_labeled_name|replace(" | ",".")|replace(" ","") }},{{ c.termination_a.name }},{{ c.termination_b.device.name }},{{ c.termination_b_type.app_labeled_name|replace(" | ",".")|replace(" ","") }},{{ c.termination_b.name }},{{ c.type }},{{ c.status }},"{{ c.label }}",{{c.color}},{{ c.length|replace("None","") }},{{ c.length_unit }}
{%- endif %}
{%- endfor %}

But the point still stands: I think that broken export templates should generate errors when you try to use them.

@candlerb
Copy link
Contributor Author

This might also be a browser-related issue. I'm using Chrome 95 under macOS 10.14.6.

I've just discovered that after the download has completed, if I switch to the "Filters" tab, change the filter, and switch back to the "Records" tab, I then see an error message:

image

However, the download did still complete (using the default export format)

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Nov 12, 2021
@jeremystretch jeremystretch self-assigned this Nov 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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