]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
allow txn argument as suggested by @rthalley 781/head
authorJakob Schlyter <jakob@kirei.se>
Mon, 21 Feb 2022 18:35:34 +0000 (19:35 +0100)
committerJakob Schlyter <jakob@kirei.se>
Mon, 21 Feb 2022 18:37:40 +0000 (19:37 +0100)
dns/zone.py
tests/test_zone.py

index c8f576a080b5c532df0694cfd916ee1e43103936..6a154cedc8039377eb2723f31050c9e0625fd48e 100644 (file)
@@ -713,7 +713,7 @@ class Zone(dns.transaction.TransactionManager):
         if self.get_rdataset(name, dns.rdatatype.NS) is None:
             raise NoNS
 
-    def get_soa(self):
+    def get_soa(self, txn=None):
         """Get the zone SOA RR.
 
         Raises ``dns.zone.NoSOA`` if there is no SOA RRset.
@@ -724,7 +724,10 @@ class Zone(dns.transaction.TransactionManager):
             origin_name = dns.name.empty
         else:
             origin_name = self.origin
-        soa = self.get_rdataset(origin_name, dns.rdatatype.SOA)
+        if txn:
+            soa = txn.get(origin_name, dns.rdatatype.SOA)
+        else:
+            soa = self.get_rdataset(origin_name, dns.rdatatype.SOA)
         if soa is None:
             raise NoSOA
         return soa[0]
index 6ef669b6c5c826d4146f266dd12ff9119099ab73..88b1e58ebe2b76cc666a111a28f28a6ab430f97f 100644 (file)
@@ -1069,6 +1069,15 @@ class VersionedZoneTestCase(unittest.TestCase):
         self.assertTrue(soa.rdtype, dns.rdatatype.SOA)
         self.assertEqual(soa.serial, 1)
 
+    def testGetSoaTxn(self):
+        z = dns.zone.from_text(example_text, 'example.', relativize=True,
+                               zone_factory=dns.versioned.Zone)
+        with z.reader(serial=1) as txn:
+            soa = z.get_soa(txn)
+            self.assertTrue(soa.rdtype, dns.rdatatype.SOA)
+            self.assertEqual(soa.serial, 1)
+
+
     def testGetSoaEmptyZone(self):
         z = dns.zone.Zone('example.')
         with self.assertRaises(dns.zone.NoSOA):