diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3fef1..8e25a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v1.?.0 - 2023-??-?? - * Record.lenient property added similar to other common/standard _octodns data +* Fix bug with Record.copy when values is an empty list [] ## v1.3.0 - 2023-11-14 - New and improved processors diff --git a/octodns/record/base.py b/octodns/record/base.py index 6f83578..d203cea 100644 --- a/octodns/record/base.py +++ b/octodns/record/base.py @@ -296,7 +296,10 @@ class ValuesMixin(object): try: values = data['values'] except KeyError: - values = [data['value']] + try: + values = [data['value']] + except KeyError: + values = [] self.values = sorted(self._value_type.process(values)) def changes(self, other, target): diff --git a/tests/test_octodns_record.py b/tests/test_octodns_record.py index 66f0b9f..0fe3d57 100644 --- a/tests/test_octodns_record.py +++ b/tests/test_octodns_record.py @@ -338,6 +338,17 @@ class TestRecord(TestCase): del b._octodns['key']['second'] self.assertNotEqual(a.data, b.data) + def test_record_copy_with_no_values(self): + txt = Record.new( + self.zone, + 'txt', + {'ttl': 45, 'type': 'TXT', 'values': []}, + lenient=True, + ) + + dup = txt.copy() + self.assertEqual(txt.values, dup.values) + def test_change(self): existing = Record.new( self.zone, 'txt', {'ttl': 44, 'type': 'TXT', 'value': 'some text'} @@ -631,10 +642,9 @@ class TestRecordValidation(TestCase): lenient=True, ) - # __init__ may still blow up, even if validation is lenient - with self.assertRaises(KeyError) as ctx: - Record.new(self.zone, 'www', {'type': 'A', 'ttl': -1}, lenient=True) - self.assertEqual(('value',), ctx.exception.args) + # empty values is allowed with lenient + r = Record.new(self.zone, 'www', {'type': 'A', 'ttl': -1}, lenient=True) + self.assertEqual([], r.values) # no exception if we're in lenient mode from config Record.new(