diff options
| author | Michael Trier <mtrier@gmail.com> | 2008-10-04 01:49:14 +0000 |
|---|---|---|
| committer | Michael Trier <mtrier@gmail.com> | 2008-10-04 01:49:14 +0000 |
| commit | 56e88ed7c3b4bd6890087d6d2ced6514076d56c3 (patch) | |
| tree | 34e5af842693cedbf4b272ad5e4f6c0d5d446b1a /lib/sqlalchemy | |
| parent | 7005a9a42fdf46fbd6925c995300c01ae56995f9 (diff) | |
| download | sqlalchemy-56e88ed7c3b4bd6890087d6d2ced6514076d56c3.tar.gz | |
Allowed column types to be callables. Fixes #1165.
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/schema.py | 10 | ||||
| -rw-r--r-- | lib/sqlalchemy/types.py | 5 |
2 files changed, 10 insertions, 5 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index bb97943eb..d859b9061 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -547,9 +547,13 @@ class Column(SchemaItem, expression._ColumnClause): "May not pass name positionally and as a keyword.") name = args.pop(0) if args: - if (isinstance(args[0], types.AbstractType) or - (isinstance(args[0], type) and - issubclass(args[0], types.AbstractType))): + coltype = args[0] + if callable(coltype): + coltype = args[0]() + + if (isinstance(coltype, types.AbstractType) or + (isinstance(coltype, type) and + issubclass(coltype, types.AbstractType))): if type_ is not None: raise exc.ArgumentError( "May not pass type_ positionally and as a keyword.") diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index a7243f279..fe6cc7b53 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -246,9 +246,10 @@ class MutableType(object): def to_instance(typeobj): if typeobj is None: return NULLTYPE - elif isinstance(typeobj, type): + + try: return typeobj() - else: + except TypeError: return typeobj def adapt_type(typeobj, colspecs): |
