]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed a bug regarding column annotations which in particular
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 3 Feb 2013 01:06:31 +0000 (20:06 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 3 Feb 2013 01:06:31 +0000 (20:06 -0500)
could impact some usages of the new :func:`.orm.remote` and
:func:`.orm.local` annotation functions, where annotations
could be lost when the column were used in a subsequent
expression.
[ticket:2660]

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/util.py
test/sql/test_selectable.py

index e35de3b2d56f49f036a57444828a96c6a9ea6ede..52414be6d6c4b610a513cd04e0422482ad23e9e3 100644 (file)
@@ -6,6 +6,16 @@
 .. changelog::
     :version: 0.8.0
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 2660, 1768
+
+      Fixed a bug regarding column annotations which in particular
+      could impact some usages of the new :func:`.orm.remote` and
+      :func:`.orm.local` annotation functions, where annotations
+      could be lost when the column were used in a subsequent
+      expression.
+
     .. change::
         :tags: bug, mysql, gae
         :tickets: 2649
index aab1ae5ba3dfdc1165a2b8fc74865e409e143ba4..fd138cfec6b3bfd713b2bc5154ce546abe8898b7 100644 (file)
@@ -449,7 +449,7 @@ class Annotated(object):
     def _with_annotations(self, values):
         clone = self.__class__.__new__(self.__class__)
         clone.__dict__ = self.__dict__.copy()
-        expression.ColumnElement.comparator._reset(self)
+        expression.ColumnElement.comparator._reset(clone)
         clone._annotations = values
         return clone
 
index 7857681f367a2996339b63128f81bb065bd9e3f9..30052a8068b4e5a6f20fe706b849b1f03caf0f7e 100644 (file)
@@ -1556,3 +1556,34 @@ class AnnotationsTest(fixtures.TestBase):
         # also pass, [ticket:2425]
         eq_(str(or_(b, b._annotate({"foo": "bar"}))),
             ":bind_1 OR :bind_1")
+
+    def test_comparators_cleaned_out_construction(self):
+        c = column('a')
+
+        comp1 = c.comparator
+
+        c1 = c._annotate({"foo": "bar"})
+        comp2 = c1.comparator
+        assert comp1 is not comp2
+
+    def test_comparators_cleaned_out_reannotate(self):
+        c = column('a')
+
+        c1 = c._annotate({"foo": "bar"})
+        comp1 = c1.comparator
+
+        c2 = c1._annotate({"bat": "hoho"})
+        comp2 = c2.comparator
+
+        assert comp1 is not comp2
+
+    def test_comparator_cleanout_integration(self):
+        c = column('a')
+
+        c1 = c._annotate({"foo": "bar"})
+        comp1 = c1.comparator
+
+        c2 = c1._annotate({"bat": "hoho"})
+        comp2 = c2.comparator
+
+        assert (c2 == 5).left._annotations == {"foo": "bar", "bat": "hoho"}