Delete blank comments. Fix for ngoduykhanh/PowerDNS-Admin#919 (#920)

This commit is contained in:
jyoung15 2021-05-07 17:43:44 -04:00 committed by GitHub
parent f3a98eb692
commit 32983635c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -311,13 +311,26 @@ class Record(object):
new_rrsets, del_rrsets = self.compare(domain_name, submitted_records)
# Remove blank comments from rrsets for compatibility with some backends
def remove_blank_comments(rrset):
if not rrset['comments']:
del rrset['comments']
elif isinstance(rrset['comments'], list):
# Merge all non-blank comment values into a list
merged_comments = [
v
for c in rrset['comments']
for v in c.values()
if v
]
# Delete comment if all values are blank (len(merged_comments) == 0)
if not merged_comments:
del rrset['comments']
for r in new_rrsets['rrsets']:
if not r['comments']:
del r['comments']
remove_blank_comments(r)
for r in del_rrsets['rrsets']:
if not r['comments']:
del r['comments']
remove_blank_comments(r)
# Submit the changes to PDNS API
try: