summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorDaniel Knell <contact@danielknell.co.uk>2018-02-05 09:25:47 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-02-05 09:27:27 -0500
commit2826484206b9211062d6228afea3f5d25ddc6030 (patch)
tree3b0e6a0b0de42b0654af9db036380ec8402c004c /lib/sqlalchemy/sql
parent56ff3c5270b4393c1ae800756f3619583a0fb255 (diff)
downloadsqlalchemy-2826484206b9211062d6228afea3f5d25ddc6030.tar.gz
fix handling of native enum aliases in sqlalchemy enum columns
Fixed bug where the :class:`.Enum` type wouldn't handle enum "aliases" correctly, when more than one key refers to the same value. Pull request courtesy Daniel Knell. Fixes: #4180 Change-Id: Ia716c00ca6c67aeab56965f0fdd575ecb7c71416 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/420
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index e11a59dac..ac915c73a 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -1352,15 +1352,18 @@ class Enum(Emulated, String, SchemaType):
self.enums = list(values)
self._valid_lookup = dict(
- zip(objects, values)
+ zip(reversed(objects), reversed(values))
)
+
self._object_lookup = dict(
- (value, key) for key, value in self._valid_lookup.items()
- )
- self._valid_lookup.update(
- [(value, value) for value in self._valid_lookup.values()]
+ zip(values, objects)
)
+ self._valid_lookup.update([
+ (value, self._valid_lookup[self._object_lookup[value]])
+ for value in values
+ ])
+
@property
def native(self):
return self.native_enum