Repository: netbox-community/netbox
Pull request: Fixes #8391: Install date should appear empty when exported
<!--
    Thank you for your interest in contributing to NetBox! Please note
    that our contribution policy requires that a feature request or bug
    report be opened for approval prior to filing a pull request. This
    helps avoid wasting time and effort on something that we might not
    be able to accept.

    Please indicate the relevant feature request or bug report below.
    IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR
    FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED.
-->
### Fixes: #8391
<!--
    Please include a summary of the proposed changes below.
-->
Set the default value to export installed_date values as empty when they are null


Problem statement:
Circuit Install Date set to NULL exports to csv as â€”
### NetBox version

v3.1.6

### Python version

3.9

### Steps to Reproduce

1. Create a circuit with no Install Date
2. Export circuits to CSV
3. Notice Install Date Field value displayed as `â€”`

### Expected Behavior

Install Date shows as NULL or empty

### Observed Behavior

Install Date shows as `â€”`

Hints from issue discussion:
Weird, I get an emdash symbol (—), which we use as a placeholder in the table. This is still wrong though; it should be null.
HI, I can work on fixing this bug during the weekend.

Commit message: Set install_date default value as empty string

Patch to review:
diff --git a/netbox/circuits/tables.py b/netbox/circuits/tables.py
index 889792be3ab..ef34fb90808 100644
--- a/netbox/circuits/tables.py
+++ b/netbox/circuits/tables.py
@@ -140,6 +140,9 @@ class CircuitTable(BaseTable):
         template_code=CIRCUITTERMINATION_LINK,
         verbose_name='Side Z'
     )
+    install_date = tables.DateColumn(
+        default=''
+    )
     commit_rate = CommitRateColumn()
     comments = MarkdownColumn()
     tags = TagColumn(


Code review comments:
diff_hunk: @@ -140,6 +140,9 @@ class CircuitTable(BaseTable):
         template_code=CIRCUITTERMINATION_LINK,
         verbose_name='Side Z'
     )
+    install_date = tables.DateColumn(
+        default=''
path: netbox/circuits/tables.py
text: @user1:
Unfortunately this approach removes the default placeholder (&mdash;) in the table when rendered in the UI, which we want to keep.

It looks like DateColumn inherits from TemplateColumn: The ideal fix for this might actually be to fix it upstream in django-tables2 by adding a `value()` method to DateColumn to better handle null values.

@author:
Yes, I agree in that it might be better to fix it upstream. This behavior will occur again in the case of exporting other null date fields, like date_added in the Aggregate model. 

I can go and open an issue there. 

@author:
The django-tables2 library doesn't seem to very active at the moment.

What do you think of implementing a custom DateColumn and improving the handling of null values within the project? 

It could be added into the utilities/tables.py module. 

@user1:
I'd rather avoid that, but it would be a reasonable short-term fix. Do you want me to keep #8391 assigned to you?

@author:
I don't like it too much either, but sure it can be a short-term fix. Yes please keep it assigned to me, I can work on it this weekend. 

@user1:
Thanks!

@author:
This is the best way I found to handle null values for all fields of type Date and DateTime, feel free to give comments on the approach. 

@user1:
Looks great to me! Thanks for your work.