]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
redid the _for_ddl String/Text deprecation warning correctly [ticket:912]
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Jan 2008 18:09:49 +0000 (18:09 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 9 Jan 2008 18:09:49 +0000 (18:09 +0000)
16 files changed:
CHANGES
lib/sqlalchemy/databases/access.py
lib/sqlalchemy/databases/firebird.py
lib/sqlalchemy/databases/informix.py
lib/sqlalchemy/databases/maxdb.py
lib/sqlalchemy/databases/mssql.py
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/oracle.py
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/databases/sybase.py
lib/sqlalchemy/logging.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/types.py
test/engine/reflection.py
test/sql/testtypes.py

diff --git a/CHANGES b/CHANGES
index d90bbe6072fda7cb20b648e868a44a78f6d52b27..cbceea4d998135db3283d2877a43a283da8035ed 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,7 +8,8 @@ CHANGES
       number rules
 - sql
     - Text type is properly exported now and does not raise a warning
-      on DDL create
+      on DDL create; String types with no length only raise warnings during
+      CREATE TABLE [ticket:912]
       
     - fixed bug in union() so that select() statements which don't derive
       from FromClause objects can be unioned
index 78e3a99970ece49f5c4b09be69459e0c8b14e6c7..bf972a1c34643fb58396c7d9f4e4448e3d755374 100644 (file)
@@ -378,7 +378,7 @@ class AccessCompiler(compiler.DefaultCompiler):
 
 class AccessSchemaGenerator(compiler.SchemaGenerator):
     def get_column_specification(self, column, **kwargs):
-        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
 
         # install a sequence if we have an implicit IDENTITY column
         if (not getattr(column.table, 'has_sequence', False)) and column.primary_key and \
index 24740017944052ebe69c825a11190395171f29a1..5e231e8728f19e77343e564325a8922049733dab 100644 (file)
@@ -585,7 +585,7 @@ class FBSchemaGenerator(sql.compiler.SchemaGenerator):
 
     def get_column_specification(self, column, **kwargs):
         colspec = self.preparer.format_column(column)
-        colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+        colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
 
         default = self.get_column_default_string(column)
         if default is not None:
index 3ad490f44b29d4f7b66ca3d66545851a94558484..f27e7a5b8913e23c263ca3d7fd27f09f355474c3 100644 (file)
@@ -434,7 +434,7 @@ class InfoSchemaGenerator(compiler.SchemaGenerator):
             colspec += " SERIAL"
             self.has_serial = True
         else:
-            colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+            colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
             default = self.get_column_default_string(column)
             if default is not None:
                 colspec += " DEFAULT " + default
index b5d397d545601f22b4d02f2c837a16b45624ea61..be1c4e70c155c333e7d0db6b3de6d0af6c797e27 100644 (file)
@@ -953,7 +953,7 @@ class MaxDBIdentifierPreparer(compiler.IdentifierPreparer):
 class MaxDBSchemaGenerator(compiler.SchemaGenerator):
     def get_column_specification(self, column, **kw):
         colspec = [self.preparer.format_column(column),
-                   column.type.dialect_impl(self.dialect).get_col_spec()]
+                   column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()]
 
         if not column.nullable:
             colspec.append('NOT NULL')
index d90c286b153c73c19ec7d9e5802890b2bdd9f1e0..7aeedad981b50c8db8104f91d77c61def7652220 100644 (file)
@@ -956,7 +956,7 @@ class MSSQLCompiler(compiler.DefaultCompiler):
 
 class MSSQLSchemaGenerator(compiler.SchemaGenerator):
     def get_column_specification(self, column, **kwargs):
-        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
         
         # install a IDENTITY Sequence if we have an implicit IDENTITY column
         if (not getattr(column.table, 'has_sequence', False)) and column.primary_key and \
index 41b35156ea3ecd4f27795bd46eb91c4e6987298e..588ea341dc0876fb34c270b969fd68a8c23133f3 100644 (file)
@@ -1956,7 +1956,7 @@ class MySQLSchemaGenerator(compiler.SchemaGenerator):
         """Builds column DDL."""
 
         colspec = [self.preparer.format_column(column),
-                   column.type.dialect_impl(self.dialect).get_col_spec()]
+                   column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()]
 
         default = self.get_column_default_string(column)
         if default is not None:
index 79a276d62db3da70f8961a2b383331fe02017212..7ac8f89518b3cdced178e5bb0ea6971d7c7d7d57 100644 (file)
@@ -690,7 +690,7 @@ class OracleCompiler(compiler.DefaultCompiler):
 class OracleSchemaGenerator(compiler.SchemaGenerator):
     def get_column_specification(self, column, **kwargs):
         colspec = self.preparer.format_column(column)
-        colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+        colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
         default = self.get_column_default_string(column)
         if default is not None:
             colspec += " DEFAULT " + default
index eacd0c7e11c76aabef1bf9cc8212157601351087..3c0314e64a46cf5c949518f32d2f1f305cc675b1 100644 (file)
@@ -115,7 +115,7 @@ class PGArray(sqltypes.Concatenable, sqltypes.TypeEngine):
             item_type = item_type()
         self.item_type = item_type
         
-    def dialect_impl(self, dialect):
+    def dialect_impl(self, dialect, **kwargs):
         impl = self.__class__.__new__(self.__class__)
         impl.__dict__.update(self.__dict__)
         impl.item_type = self.item_type.dialect_impl(dialect)
@@ -694,7 +694,7 @@ class PGSchemaGenerator(compiler.SchemaGenerator):
             else:
                 colspec += " SERIAL"
         else:
-            colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+            colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
             default = self.get_column_default_string(column)
             if default is not None:
                 colspec += " DEFAULT " + default
index b357f48decdebed0613a030b5b9d1efe70c2ef72..92645e524f1aee5f399d2dba402bae5979db32bd 100644 (file)
@@ -386,7 +386,7 @@ class SQLiteCompiler(compiler.DefaultCompiler):
 class SQLiteSchemaGenerator(compiler.SchemaGenerator):
 
     def get_column_specification(self, column, **kwargs):
-        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+        colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
         default = self.get_column_default_string(column)
         if default is not None:
             colspec += " DEFAULT " + default
index c170a9723ce7019561a39089d82f6f82e60b1db4..f461125aa3fd12f2e6c031b64b47245dd11fa233 100644 (file)
@@ -827,7 +827,7 @@ class SybaseSQLSchemaGenerator(compiler.SchemaGenerator):
             #colspec += " numeric(30,0) IDENTITY"
             colspec += " Integer IDENTITY"
         else:
-            colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+            colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
             
         if not column.nullable:
             colspec += " NOT NULL"
index 7c2bd636c51cec7d74881154f8cc9d34337e97bc..57e7bcfd7da59517b3cd374063ccf3ea9d5bb9ab 100644 (file)
@@ -31,7 +31,7 @@ import sys, warnings
 # py2.5 absolute imports will fix....
 logging = __import__('logging')
 
-
+# why is this in the "logging" module?
 class SADeprecationWarning(DeprecationWarning):
     pass
     
index 70343a7b4ddf22da49e8ee1922d55bd72be50ab6..35a12efe393071af82dd72c531046baf283ba923 100644 (file)
@@ -286,7 +286,7 @@ class DefaultCompiler(engine.Compiled):
         return index.name
 
     def visit_typeclause(self, typeclause, **kwargs):
-        return typeclause.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
+        return typeclause.type.dialect_impl(self.dialect).get_col_spec()
 
     def visit_textclause(self, textclause, **kwargs):
         if textclause.typemap is not None:
index b2819ece0add043448ddd6b5c8c0c88fc15d2237..1a5d0ab56123a68cff12f59970cbbe7b31b9d7bb 100644 (file)
@@ -392,7 +392,7 @@ class String(Concatenable, TypeEngine):
 
     def dialect_impl(self, dialect, **kwargs):
         _for_ddl = kwargs.pop('_for_ddl', False)
-        if self.length is None:
+        if _for_ddl and self.length is None:
             warn_deprecated("Using String type with no length for CREATE TABLE is deprecated; use the Text type explicitly")
         return TypeEngine.dialect_impl(self, dialect, **kwargs)
         
index 9b560e6689e054e39fce107f66aa8c2b1be495d0..8b4fec50de119e2473b9ea1a672b543216827666 100644 (file)
@@ -7,6 +7,7 @@ from sqlalchemy import types as sqltypes
 from testlib import *
 from testlib import engines
 
+
 class ReflectionTest(PersistTest):
 
     @testing.exclude('mysql', '<', (4, 1, 1))
@@ -24,7 +25,7 @@ class ReflectionTest(PersistTest):
             deftype = Integer
 
         if use_string_defaults:
-            deftype2 = String
+            deftype2 = Text
             defval2 = "im a default"
             deftype3 = Date
             if testing.against('oracle'):
@@ -44,12 +45,12 @@ class ReflectionTest(PersistTest):
             Column('user_name', VARCHAR(20), nullable = False),
             Column('test1', CHAR(5), nullable = False),
             Column('test2', FLOAT(5), nullable = False),
-            Column('test3', TEXT),
+            Column('test3', Text),
             Column('test4', DECIMAL, nullable = False),
             Column('test5', TIMESTAMP),
             Column('parent_user_id', Integer, ForeignKey('engine_users.user_id')),
             Column('test6', DateTime, nullable = False),
-            Column('test7', String),
+            Column('test7', Text),
             Column('test8', Binary),
             Column('test_passivedefault', deftype, PassiveDefault(defval)),
             Column('test_passivedefault2', Integer, PassiveDefault("5")),
index fc1da5578b87ad9af4f4c526be20f39dacf6661e..7bd012f42f1e0c288f863cc0fa54d34b2245d28b 100644 (file)
@@ -660,7 +660,40 @@ class DateTest(AssertMixin):
         finally:
             t.drop(checkfirst=True)
 
+class StringTest(AssertMixin):
+    def test_nolen_string_deprecated(self):
+        metadata = MetaData(testbase.db)
+        foo =Table('foo', metadata, 
+            Column('one', String))
+
+        import warnings
+        from sqlalchemy.logging import SADeprecationWarning
+
+        warnings.filterwarnings("error", r"Using String type with no length.*")
+
+        # no warning
+        select([func.count("*")], bind=testbase.db).execute()
+
+        try:
+            # warning during CREATE
+            foo.create()
+            assert False
+        except SADeprecationWarning, e:
+            assert "Using String type with no length" in str(e)
+        
+        bar = Table('bar', metadata, Column('one', String(40)))
+
+        try:
+            # no warning
+            bar.create()
 
+            # no warning for non-lengthed string
+            select([func.count("*")], from_obj=bar).execute()
+        finally:
+            bar.drop()
+            warnings.filterwarnings("always", r"Using String type with no length.*")
+            
+            
 class NumericTest(AssertMixin):
     def setUpAll(self):
         global numeric_table, metadata