]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #4406 Added port comparison in __eq__() and added _ne__() method to class URL 4515/head
authorSanjana <sanjana0796@gmail.com>
Sun, 24 Feb 2019 11:48:57 +0000 (17:18 +0530)
committersanjana <sanjana0796@gmail.com>
Mon, 25 Feb 2019 06:23:26 +0000 (11:53 +0530)
doc/build/changelog/unreleased_13/4406.rst [new file with mode: 0644]
lib/sqlalchemy/engine/url.py
test/engine/test_parseconnect.py

diff --git a/doc/build/changelog/unreleased_13/4406.rst b/doc/build/changelog/unreleased_13/4406.rst
new file mode 100644 (file)
index 0000000..c01179d
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+   :tags: bug, engine
+   :tickets: 4406
+
+   Comparing two objects of :class:`.URL` using ``__eq__()`` did not take port
+   number into consideration, two objects differing only by port number were
+   considered equal. Port comparison is now added in ``__eq__()`` method of
+   :class:`.URL`, objects differing by port number are now not equal. Additionally,
+   ``__ne__()`` was not implemented for :class:`.URL` which caused unexpected
+   result when ``!=`` was used in Python2, since there are no implied
+   relationships among the comparison operators in Python2.
index 536e21c3867918b72e6e084881c4cf4a64b4d7b4..16b7c051a90630809e00fa5e0cc28bda42dee373 100644 (file)
@@ -120,8 +120,12 @@ class URL(object):
             and self.host == other.host
             and self.database == other.database
             and self.query == other.query
+            and self.port == other.port
         )
 
+    def __ne__(self, other):
+        return not self == other
+
     @property
     def password(self):
         if self.password_original is None:
index be90378c93080246f36a2fc5c5712567367e2a2c..913e9ad8670d21d28cd6616dabf52194510381ca 100644 (file)
@@ -8,7 +8,7 @@ from sqlalchemy.dialects import plugins
 from sqlalchemy.dialects import registry
 from sqlalchemy.engine.default import DefaultDialect
 import sqlalchemy.engine.url as url
-from sqlalchemy.testing import assert_raises
+from sqlalchemy.testing import assert_raises, ne_
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
 from sqlalchemy.testing import is_
@@ -146,6 +146,26 @@ class ParseConnectTest(fixtures.TestBase):
         )
 
 
+class UrlTest(fixtures.TestBase):
+    def test_comparison(self):
+        components = ('drivername', 'username', 'password', 'host',
+                      'database', 'query', 'port')
+
+        common_url = "dbtype://username:password" \
+                     "@[2001:da8:2004:1000:202:116:160:90]:80/database?foo=bar"
+        url1 = url.make_url(common_url)
+        url2 = url.make_url(common_url)
+
+        eq_(url1, url2)
+        assert not url1 != url2
+
+        for curr_component in components:
+            setattr(url2, curr_component, 'new_changed_value')
+            ne_(url1, url2)
+            assert not url1 == url2
+            setattr(url2, curr_component, getattr(url1, curr_component))
+
+
 class DialectImportTest(fixtures.TestBase):
     def test_import_base_dialects(self):
         # the globals() somehow makes it for the exec() + nose3.