[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ mapper_class must be a subclass of MapperClassBase

Andreas Jung andreas at andreas-jung.com
Mon Apr 30 10:37:24 EDT 2007


Log message for revision 74924:
  mapper_class must be a subclass of MapperClassBase
  

Changed:
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py
  U   z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py

-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt	2007-04-30 12:21:15 UTC (rev 74923)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt	2007-04-30 14:37:23 UTC (rev 74924)
@@ -1,3 +1,8 @@
+0.1.11 (unreleased)
+
+   - added check for the 'mapper_class' attribute (classes from now
+     on must be a subclass of MapperClassBase)
+
 0.1.10 (30.04.2007)
 
    - fixed a bug in mapper (unfortunately I forgot to commit a

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py	2007-04-30 12:21:15 UTC (rev 74923)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/model.py	2007-04-30 14:37:23 UTC (rev 74924)
@@ -14,6 +14,8 @@
 
 import sqlalchemy
 
+from mapper import MappedClassBase
+
 __all__ = ('Model',)
 
 
@@ -56,8 +58,8 @@
         if table is not None and not isinstance(table, sqlalchemy.Table):
             raise TypeError("'table' must be an instance or sqlalchemy.Table or None")
 
-        if mapper_class is not None and not issubclass(mapper_class, object):
-            raise TypeError("'mapper_class' must be a new-style class")
+        if mapper_class is not None and not issubclass(mapper_class, MappedClassBase):
+            raise TypeError("'mapper_class' must be a subclass of MappedClassBase")
         
         if relations is not None:
             for r in relations:

Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py	2007-04-30 12:21:15 UTC (rev 74923)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/tests/testSQLAlchemy.py	2007-04-30 14:37:23 UTC (rev 74924)
@@ -21,6 +21,7 @@
 from z3c.sqlalchemy.interfaces import ISQLAlchemyWrapper
 from z3c.sqlalchemy.postgres import PythonPostgresWrapper,  ZopePostgresWrapper
 from z3c.sqlalchemy.base import BaseWrapper
+from z3c.sqlalchemy.mapper import MappedClassBase
 from z3c.sqlalchemy import createSAWrapper, Model, registerSAWrapper, getSAWrapper
 
 
@@ -85,7 +86,7 @@
 
     def testMapperWithCustomModel(self):
 
-        class myUser(object): 
+        class myUser(MappedClassBase): 
             pass
 
         M = Model()
@@ -96,6 +97,15 @@
         self.assertEqual(User, myUser)
 
 
+    def testCustomMapperClassWithWrongType(self):
+
+        class myUser(object): 
+            pass
+
+        M = Model()
+        self.assertRaises(TypeError, M.add, 'user', mapper_class=myUser)
+
+
     def testGetMappers(self):
 
         db = createSAWrapper('sqlite:///test')



More information about the Checkins mailing list