diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-06-04 20:52:30 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-06-04 20:52:30 -0400 |
commit | 09080baad1a9f910a5a406dfad9241104ccbc6d8 (patch) | |
tree | 97bdbcc41d914e83cecede45033dd91732748e77 /lib/sqlalchemy | |
parent | c0f922116004d762991bdfe56da31d3b70e8c01d (diff) | |
download | sqlalchemy-09080baad1a9f910a5a406dfad9241104ccbc6d8.tar.gz |
- Adjusted the __contains__() method of
a RowProxy result row such that no exception
throw is generated internally;
NoSuchColumnError() also will generate its
message regardless of whether or not the column
construct can be coerced to a string.
[ticket:2178]. Also in 0.6.8.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 16 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 9 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index e23465c22..04636b5e5 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -2578,7 +2578,7 @@ class ResultMetaData(object): if self._keymap.setdefault(name, rec) is not rec: self._keymap[name] = (processor, None) - def _key_fallback(self, key): + def _key_fallback(self, key, raiseerr=True): map = self._keymap result = None if isinstance(key, basestring): @@ -2592,8 +2592,12 @@ class ResultMetaData(object): elif hasattr(key, 'name') and key.name.lower() in map: result = map[key.name.lower()] if result is None: - raise exc.NoSuchColumnError( - "Could not locate column in row for column '%s'" % key) + if raiseerr: + raise exc.NoSuchColumnError( + "Could not locate column in row for column '%s'" % + expression._string_or_unprintable(key)) + else: + return None else: map[key] = result return result @@ -2602,11 +2606,7 @@ class ResultMetaData(object): if key in self._keymap: return True else: - try: - self._key_fallback(key) - return True - except exc.NoSuchColumnError: - return False + return self._key_fallback(key, False) is not None def __getstate__(self): return { diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 38eb71da8..ec0801405 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1207,6 +1207,15 @@ def _escape_for_generated(x): else: return x.replace('%', '%%') +def _string_or_unprintable(element): + if isinstance(element, basestring): + return element + else: + try: + return str(element) + except: + return "unprintable element %r" % element + def _clone(element): return element._clone() |