]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add __copy__, __deepcopy__ to URL. Fixes: #7400 7401/head
authorTom Ritchford <tom@swirly.com>
Sun, 5 Dec 2021 17:59:56 +0000 (18:59 +0100)
committerTom Ritchford <tom@swirly.com>
Sun, 5 Dec 2021 18:02:15 +0000 (19:02 +0100)
lib/sqlalchemy/engine/url.py
test/engine/test_parseconnect.py

index 7cdf25c21aadc6e4937c53dc98230b60f9accb9f..9dad7fad235ebb53c7a50bec85baa7facec3b713 100644 (file)
@@ -560,6 +560,20 @@ class URL(
     def __repr__(self):
         return self.render_as_string()
 
+    def __copy__(self):
+        return __class__.create(
+            self.drivername,
+            self.username,
+            self.password,
+            self.host,
+            self.port,
+            self.database,
+            self.query,
+        )
+
+    def __deepcopy__(self, memo):
+        return self.__copy__()
+
     def __hash__(self):
         return hash(str(self))
 
index f12d32d5d0e558cf12d9375288fafd0c43ec9673..ed701f8173a743e1d9c325774a35bd03bc7fb53e 100644 (file)
@@ -1,6 +1,8 @@
 from unittest.mock import call
 from unittest.mock import MagicMock
 from unittest.mock import Mock
+import copy
+import warnings
 
 import sqlalchemy as tsa
 from sqlalchemy import create_engine
@@ -196,6 +198,18 @@ class URLTest(fixtures.TestBase):
         is_true(url1 != url3)
         is_false(url1 == url3)
 
+    def test_warnings(self):
+        assert_raises(
+            exc.SADeprecationWarning,
+            url.URL,
+            "dbtype"
+        )
+        url1 = url.URL.create("dbtype")
+        url2 = copy.copy(url1)
+        url3 = copy.deepcopy(url2)
+        is_true(url1 == url2)
+        is_true(url2 == url3)
+
     @testing.combinations(
         "drivername",
         "username",