summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorndparker <ndparker@users.noreply.github.com>2014-09-24 00:13:40 +0200
committerndparker <ndparker@users.noreply.github.com>2014-10-05 00:54:09 +0200
commit00018f0748a2eac323248c5d80c28a127907344a (patch)
tree1b0ce2f321f7951b1992224526fe08f7b60e18b2
parent360477cc3af826b5056039b9a19ec3ecb2b94ede (diff)
downloadsqlalchemy-pr/141.tar.gz
specialize schema reflection warningspr/141
-rw-r--r--lib/sqlalchemy/dialects/firebird/base.py5
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py4
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py14
-rw-r--r--lib/sqlalchemy/dialects/oracle/base.py7
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py14
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py4
-rw-r--r--lib/sqlalchemy/dialects/sybase/base.py5
-rw-r--r--lib/sqlalchemy/engine/reflection.py8
-rw-r--r--lib/sqlalchemy/exc.py32
-rw-r--r--lib/sqlalchemy/testing/assertions.py3
10 files changed, 71 insertions, 25 deletions
diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py
index 36229a105..c055bb2bb 100644
--- a/lib/sqlalchemy/dialects/firebird/base.py
+++ b/lib/sqlalchemy/dialects/firebird/base.py
@@ -609,8 +609,9 @@ class FBDialect(default.DefaultDialect):
colspec = row['ftype'].rstrip()
coltype = self.ischema_names.get(colspec)
if coltype is None:
- util.warn("Did not recognize type '%s' of column '%s'" %
- (colspec, name))
+ util.warn(exc.SAUnknownTypeReflectionWarning(
+ "Did not recognize type '%s' of column '%s'" %
+ (colspec, name)))
coltype = sqltypes.NULLTYPE
elif issubclass(coltype, Integer) and row['fprec'] != 0:
coltype = NUMERIC(
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index ba3050ae5..faa342659 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -1600,9 +1600,9 @@ class MSDialect(default.DefaultDialect):
kwargs.pop('length')
if coltype is None:
- util.warn(
+ util.warn(exc.SAUnknownTypeReflectionWarning(
"Did not recognize type '%s' of column '%s'" %
- (type, name))
+ (type, name)))
coltype = sqltypes.NULLTYPE
else:
if issubclass(coltype, sqltypes.Numeric) and \
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 7ccd59abb..365155fe1 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -2904,10 +2904,14 @@ class MySQLTableDefinitionParser(object):
spec = m.groupdict()
spec['full'] = False
if not spec:
- util.warn("Unknown column definition %r" % line)
+ util.warn(exc.SAUnparsableTypeReflectionWarning(
+ "Unknown column definition %r" % line
+ ))
return
if not spec['full']:
- util.warn("Incomplete reflection of column definition %r" % line)
+ util.warn(exc.SAIncompleteTypeReflectionWarning(
+ "Incomplete reflection of column definition %r" % line
+ ))
name, type_, args, notnull = \
spec['name'], spec['coltype'], spec['arg'], spec['notnull']
@@ -2915,8 +2919,10 @@ class MySQLTableDefinitionParser(object):
try:
col_type = self.dialect.ischema_names[type_]
except KeyError:
- util.warn("Did not recognize type '%s' of column '%s'" %
- (type_, name))
+ util.warn(exc.SAUnknownTypeReflectionWarning(
+ "Did not recognize type '%s' of column '%s'" %
+ (type_, name)
+ ))
col_type = sqltypes.NullType
# Column type positional arguments eg. varchar(32)
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py
index 837a498fb..d07bd572b 100644
--- a/lib/sqlalchemy/dialects/oracle/base.py
+++ b/lib/sqlalchemy/dialects/oracle/base.py
@@ -232,7 +232,7 @@ in conjunction with the :class:`.Table` construct:
import re
-from sqlalchemy import util, sql
+from sqlalchemy import util, sql, exc
from sqlalchemy.engine import default, base, reflection
from sqlalchemy.sql import compiler, visitors, expression
from sqlalchemy.sql import (operators as sql_operators,
@@ -1137,8 +1137,9 @@ class OracleDialect(default.DefaultDialect):
try:
coltype = self.ischema_names[coltype]
except KeyError:
- util.warn("Did not recognize type '%s' of column '%s'" %
- (coltype, colname))
+ util.warn(exc.SAUnknownTypeReflectionWarning(
+ "Did not recognize type '%s' of column '%s'" %
+ (coltype, colname)))
coltype = sqltypes.NULLTYPE
cdict = {
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index b9a0d461b..fe256a249 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -2282,8 +2282,10 @@ class PGDialect(default.DefaultDialect):
if is_array:
coltype = ARRAY(coltype)
else:
- util.warn("Did not recognize type '%s' of column '%s'" %
- (attype, name))
+ util.warn(exc.SAUnknownTypeReflectionWarning(
+ "Did not recognize type '%s' of column '%s'" %
+ (attype, name)
+ ))
coltype = sqltypes.NULLTYPE
# adjust the default value
autoincrement = False
@@ -2505,17 +2507,17 @@ class PGDialect(default.DefaultDialect):
if expr:
if idx_name != sv_idx_name:
- util.warn(
+ util.warn(exc.SAUnsupportedIndexReflectionWarning(
"Skipped unsupported reflection of "
"expression-based index %s"
- % idx_name)
+ % idx_name))
sv_idx_name = idx_name
continue
if prd and not idx_name == sv_idx_name:
- util.warn(
+ util.warn(exc.SAIncompleteIndexReflectionWarning(
"Predicate of partial index %s ignored during reflection"
- % idx_name)
+ % idx_name))
sv_idx_name = idx_name
index = indexes[idx_name]
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index 817834b7d..1c6fa145a 100644
--- a/lib/sqlalchemy/dialects/sqlite/base.py
+++ b/lib/sqlalchemy/dialects/sqlite/base.py
@@ -987,10 +987,10 @@ class SQLiteDialect(default.DefaultDialect):
try:
coltype = coltype(*[int(a) for a in args])
except TypeError:
- util.warn(
+ util.warn(exc.SAIncompleteTypeReflectionWarning(
"Could not instantiate type %s with "
"reflected arguments %s; using no arguments." %
- (coltype, args))
+ (coltype, args)))
coltype = coltype()
else:
coltype = coltype()
diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py
index f65a76a27..97fd0469a 100644
--- a/lib/sqlalchemy/dialects/sybase/base.py
+++ b/lib/sqlalchemy/dialects/sybase/base.py
@@ -550,8 +550,9 @@ class SybaseDialect(default.DefaultDialect):
# if is_array:
# coltype = ARRAY(coltype)
else:
- util.warn("Did not recognize type '%s' of column '%s'" %
- (type_, name))
+ util.warn(exc.SAUnknownTypeReflectionWarning(
+ "Did not recognize type '%s' of column '%s'" %
+ (type_, name)))
coltype = sqltypes.NULLTYPE
if default:
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index c0a3240a5..6e45b6102 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -605,9 +605,9 @@ class Inspector(object):
flavor = index_d.get('type', 'index')
if include_columns and \
not set(columns).issubset(include_columns):
- util.warn(
+ util.warn(exc.SAOmittedIndexReflectionWarning(
"Omitting %s key for (%s), key covers omitted columns." %
- (flavor, ', '.join(columns)))
+ (flavor, ', '.join(columns))))
continue
# look for columns by orig name in cols_by_orig_name,
# but support columns that are in-Python only as fallback
@@ -617,11 +617,11 @@ class Inspector(object):
idx_col = cols_by_orig_name[c] \
if c in cols_by_orig_name else table.c[c]
except KeyError:
- util.warn(
+ util.warn(exc.SAIncompleteIndexReflectionWarning(
"%s key '%s' was not located in "
"columns for table '%s'" % (
flavor, c, table_name
- ))
+ )))
else:
idx_cols.append(idx_col)
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index a82bae33f..2c61def13 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -368,3 +368,35 @@ class SAPendingDeprecationWarning(PendingDeprecationWarning):
class SAWarning(RuntimeWarning):
"""Issued at runtime."""
+
+
+class SAIndexReflectionWarning(SAWarning):
+ """ Issued if an index cannot be reflected """
+
+
+class SAOmittedIndexReflectionWarning(SAIndexReflectionWarning):
+ """ Issued if an index is ignored, because of omitted columns """
+
+
+class SAIncompleteIndexReflectionWarning(SAIndexReflectionWarning):
+ """ Issued if an index is missing columns or predicates """
+
+
+class SAUnsupportedIndexReflectionWarning(SAIndexReflectionWarning):
+ """ Issued if an index type is not supported and hence not reflected """
+
+
+class SATypeReflectionWarning(SAWarning):
+ """ Issued if a type cannot be reflected """
+
+
+class SAUnknownTypeReflectionWarning(SATypeReflectionWarning):
+ """ Issued if the reflected type is not known to SQLAlchemy """
+
+
+class SAUnparsableTypeReflectionWarning(SATypeReflectionWarning):
+ """ Issued if the type info from the DB could not be parsed """
+
+
+class SAIncompleteTypeReflectionWarning(SATypeReflectionWarning):
+ """ Issued if the type reflection is incomplete """
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index bf7c27a89..96b3f7320 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -110,6 +110,9 @@ def _expect_warnings(exc_cls, messages):
real_warn = warnings.warn
def our_warn(msg, exception, *arg, **kw):
+ if isinstance(msg, Warning):
+ msg, exception = str(msg), type(msg)
+
if not issubclass(exception, exc_cls):
return real_warn(msg, exception, *arg, **kw)