From 03f37e3ae9e6be54ba885289a4258563373fc919 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Tue, 28 Nov 2023 16:27:02 -0800 Subject: [PATCH] Fix bug with Record.copy when values is an empty list [] --- CHANGELOG.md | 1 + octodns/record/base.py | 5 ++++- tests/test_octodns_record.py | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efc77c5..b0a738c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ desired and/or existing zones just prior to computing changes. * Fix an issue in MetaProcessor/Manager.include_meta where include_provider wasn't correctly taking effect +* 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(