import weakref
from .. import util
+from .. import inspection
from . import exc as orm_exc, interfaces
from .path_registry import PathRegistry
from .base import PASSIVE_NO_RESULT, SQL_OK, NEVER_SET, ATTR_WAS_SET, \
from . import base
+@inspection._self_inspects
class InstanceState(interfaces.InspectionAttr):
"""tracks state information at the instance level.
# use inspect() to detect SQLAlchemy built-in
# objects.
insp = inspection.inspect(value, False)
- if insp is not None:
+ if (
+ insp is not None and
+ # foil mock.Mock() and other impostors by ensuring
+ # the inspection target itself self-inspects
+ insp.__class__ in inspection._registrars
+ ):
raise exc.ArgumentError(
"Object %r is not legal as a SQL literal value" % value)
return NULLTYPE
from sqlalchemy.testing.util import picklers
from sqlalchemy.testing.util import round_decimal
from sqlalchemy.testing import fixtures
-
+from sqlalchemy.testing import mock
class AdaptTest(fixtures.TestBase):
types.NULLTYPE
)
+ def test_detect_coercion_not_fooled_by_mock(self):
+ m1 = mock.Mock()
+ is_(
+ bindparam('x', m1).type,
+ types.NULLTYPE
+ )
+
+
class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = 'default'