diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-22 12:47:13 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-08-22 12:47:13 -0400 |
| commit | 8712ef2f81498fe59b9636ba150833d779e60781 (patch) | |
| tree | 8e42639b148196a22d930fdef851b44686886279 /test/sql | |
| parent | e0a8030048f4ad0690d3084929441bda4c21aba2 (diff) | |
| download | sqlalchemy-8712ef2f81498fe59b9636ba150833d779e60781.tar.gz | |
- Added new checks for the common error case of passing mapped classes
or mapped instances into contexts where they are interpreted as
SQL bound parameters; a new exception is raised for this.
fixes #3321
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_types.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 0ab8ef451..90fac97c2 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -1,5 +1,6 @@ # coding: utf-8 -from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, expect_warnings +from sqlalchemy.testing import eq_, is_, assert_raises, \ + assert_raises_message, expect_warnings import decimal import datetime import os @@ -11,7 +12,7 @@ from sqlalchemy import ( BLOB, NCHAR, NVARCHAR, CLOB, TIME, DATE, DATETIME, TIMESTAMP, SMALLINT, INTEGER, DECIMAL, NUMERIC, FLOAT, REAL) from sqlalchemy.sql import ddl - +from sqlalchemy import inspection from sqlalchemy import exc, types, util, dialects for name in dialects.__all__: __import__("sqlalchemy.dialects.%s" % name) @@ -1647,6 +1648,26 @@ class ExpressionTest( assert distinct(test_table.c.data).type == test_table.c.data.type assert test_table.c.data.distinct().type == test_table.c.data.type + def test_detect_coercion_of_builtins(self): + @inspection._self_inspects + class SomeSQLAThing(object): + def __repr__(self): + return "some_sqla_thing()" + + class SomeOtherThing(object): + pass + + assert_raises_message( + exc.ArgumentError, + r"Object some_sqla_thing\(\) is not legal as a SQL literal value", + lambda: column('a', String) == SomeSQLAThing() + ) + + is_( + bindparam('x', SomeOtherThing()).type, + types.NULLTYPE + ) + class CompileTest(fixtures.TestBase, AssertsCompiledSQL): __dialect__ = 'default' |
