Displaying an unsaved record fails in `nbshell`
Closed this issue · 0 comments
peteeckel commented
Versions
NetBox Version: 4.0.3
NetBox DNS Version: 1.0.1
Python Version: 3.11.5
Describe the bug
The __str__
method throws an exception for unsaved records.
To Reproduce
(netbox) [root@dns netbox]# /opt/netbox/netbox/manage.py nbshell
### NetBox interactive shell (dns.dev.hindenburgring.com)
### Python 3.11.5 | Django 5.0.6 | NetBox 4.0.3
### lsmodels() will show available models. Use help(<model>) for more info.
>>> from netbox_dns.models import NameServer, Zone, Record
>>> ns = NameServer(name="ns1.example.com")
>>> zone = Zone(name="zone1.example.com", soa_mname=ns, soa_rname="hostmaster.example.com")
>>> record = Record(name="name1", zone=zone, type="AAAA", value="fe80::dead:beef")
>>> record
Expected result
<Record: name1.zone1.example.com [AAAA]>
Actual result
Traceback (most recent call last):
File "/usr/lib64/python3.11/code.py", line 90, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/base.py", line 588, in __repr__
return "<%s: %s>" % (self.__class__.__name__, self)
^^^^
File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 215, in __str__
name = dns_name.from_text(self.fqdn).relativize(dns_name.root).to_unicode()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/netbox/lib64/python3.11/site-packages/dns/name.py", line 1012, in from_text
raise ValueError("input to from_text() must be a string")
ValueError: input to from_text() must be a string
This is a regression caused by 45342e3. fqdn
used to be a property, but was converted to a database field in order to enable searching for fully qualified domain names, and this new field is not populated as long as the Record
object hasn't been saved.