]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The per-dialect cache used by TypeEngine to cache
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Jan 2009 16:09:14 +0000 (16:09 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 29 Jan 2009 16:09:14 +0000 (16:09 +0000)
dialect-specific types is now a WeakKeyDictionary.
This to prevent dialect objects from
being referenced forever for an application that
creates an arbitrarily large number of engines
or dialects.   There is a small performance penalty
which will be resolved in 0.6.  [ticket:1299]

CHANGES
lib/sqlalchemy/types.py
test/profiling/memusage.py

diff --git a/CHANGES b/CHANGES
index e5cc729b9ea463b80e12be94f15a4932a8df84f1..5753d30f604e651e405006b14fb4728409067116 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,14 @@ CHANGES
 - sql
     - the __selectable__() interface has been replaced entirely
       by __clause_element__().
+
+    - The per-dialect cache used by TypeEngine to cache
+      dialect-specific types is now a WeakKeyDictionary.
+      This to prevent dialect objects from 
+      being referenced forever for an application that 
+      creates an arbitrarily large number of engines
+      or dialects.   There is a small performance penalty
+      which will be resolved in 0.6.  [ticket:1299]
       
 0.5.2
 ======
index 9ffd4d1831d73503677d9b1d7a0c5631ec18c931..8d47a2cf5d37a2232c72d186c9b44c6f13bb1826 100644 (file)
@@ -24,7 +24,7 @@ __all__ = [ 'TypeEngine', 'TypeDecorator', 'AbstractType',
 import inspect
 import datetime as dt
 from decimal import Decimal as _python_Decimal
-
+import weakref
 from sqlalchemy import exc
 from sqlalchemy.util import pickle
 import sqlalchemy.util as util
@@ -125,14 +125,14 @@ class TypeEngine(AbstractType):
         try:
             return self._impl_dict[dialect]
         except AttributeError:
-            self._impl_dict = {}
+            self._impl_dict = weakref.WeakKeyDictionary()   # will be optimized in 0.6
             return self._impl_dict.setdefault(dialect, dialect.type_descriptor(self))
         except KeyError:
             return self._impl_dict.setdefault(dialect, dialect.type_descriptor(self))
 
     def __getstate__(self):
         d = self.__dict__.copy()
-        d['_impl_dict'] = {}
+        d['_impl_dict'] = weakref.WeakKeyDictionary()   # will be optimized in 0.6
         return d
 
     def get_col_spec(self):
@@ -223,7 +223,7 @@ class TypeDecorator(AbstractType):
         try:
             return self._impl_dict[dialect]
         except AttributeError:
-            self._impl_dict = {}
+            self._impl_dict = weakref.WeakKeyDictionary()   # will be optimized in 0.6
         except KeyError:
             pass
 
index 8bc2825db873e9686215f297fcf2ace8cd57e0b3..ccafc7bd7e99862c8fb97a3f60e4d1220b510945 100644 (file)
@@ -6,6 +6,8 @@ from sqlalchemy.orm.session import _sessions
 import operator
 from testlib import testing
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, PickleType
+import sqlalchemy as sa
+from sqlalchemy.sql import column
 from orm import _base
 
 
@@ -386,6 +388,15 @@ class MemUsageTest(EnsureZeroed):
             go()
         finally:
             metadata.drop_all()
+
+    def test_type_compile(self):
+        from sqlalchemy.databases.sqlite import SQLiteDialect
+        cast = sa.cast(column('x'), sa.Integer)
+        @profile_memory
+        def go():
+            dialect = SQLiteDialect()
+            cast.compile(dialect=dialect)
+        go()
         
 if __name__ == '__main__':
     testenv.main()