<p dir="auto"><strong>Describe the bug</strong><br>
We had a legacy enum with names that have spaces so we added some aliases to make coding easier.<br>
Notice the aliases have repeated values so they <a href="https://docs.python.org/3/library/enum.html#duplicating-enum-members-and-values" rel="nofollow">will not create enum elements</a>.</p>
<p dir="auto">E.g:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Names = enum.Enum(
    value='Names',
    names=[
        ('Name A', 1), ('a', 1),
        ('Name B', 2), ('b', 2),
        ('Name C', 3), ('c', 3),
    ]
)"><pre class="notranslate"><code class="notranslate">Names = enum.Enum(
    value='Names',
    names=[
        ('Name A', 1), ('a', 1),
        ('Name B', 2), ('b', 2),
        ('Name C', 3), ('c', 3),
    ]
)
</code></pre></div>
<p dir="auto">So when you <code class="notranslate">list(Names)</code>, you only see the 3 original enum names and : <code class="notranslate">Names["Name A"] is Names.a</code> meaning that <code class="notranslate">a</code> is just an alias and points to the same object.</p>
<p dir="auto">When you pass this to <code class="notranslate">name = Column(Enum(Names))</code>, it will create the 6 names on the column because<br>
<code class="notranslate">sqlalchemy.Enum._parse_into_values</code> is using the <code class="notranslate">__members__</code> atribute from enum which shows everything, including aliases.</p>
<p dir="auto">SQL output for that column:<br>
<code class="notranslate">`name` ENUM('Name A','Name B','Name C','a','b','c') NOT NULL,</code></p>
<p dir="auto"><strong>Expected behavior</strong><br>
<code class="notranslate">`name` ENUM('Name A','Name B','Name C') NOT NULL,</code></p>
<p dir="auto">I propose to use  <code class="notranslate">[e.name for e in enum_class]</code><br>
instead of <code class="notranslate">enum_class.__members__</code><br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/sqlalchemy/sqlalchemy/blob/93ea31df86fc925a9e1df2a7dc80dd39f7ae4b9e/lib/sqlalchemy/sql/sqltypes.py#L1509">sqlalchemy/lib/sqlalchemy/sql/sqltypes.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 1509
      in
      <a data-pjax="true" class="commit-tease-sha" href="/sqlalchemy/sqlalchemy/commit/93ea31df86fc925a9e1df2a7dc80dd39f7ae4b9e">93ea31d</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L1509" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="1509"></td>
          <td id="LC1509" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1">members</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">enum_class</span>.<span class="pl-s1">__members__</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto"><strong>Versions.</strong></p>
<ul dir="auto">
<li>OS: MacOS</li>
<li>Python: 3.8</li>
<li>SQLAlchemy: 1.3.23</li>
<li>Database: MySQL</li>
<li>DBAPI: pymysql</li>
</ul>
<p dir="auto"><strong>Migrated issue, originally created by Lev Panov (<a href="https://github.com/leavittx">@leavittx</a>)</strong></p>
<p dir="auto">Engine instance was created via</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!div style=&quot;font-size: 80%&quot;
Code highlighting:
  `#!python
  engine = create_engine('mssql+pyodbc://user:pass@server.com/db?driver=SQL Server', echo=True)"><pre class="notranslate"><code class="notranslate">#!div style="font-size: 80%"
Code highlighting:
  `#!python
  engine = create_engine('mssql+pyodbc://user:pass@server.com/db?driver=SQL Server', echo=True)
</code></pre></div>
<p dir="auto">When I do for example</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!div style=&quot;font-size: 80%&quot;
Code highlighting:
  `#!python
  session.query(User).filter(or_(expression.false(), expression.true())).all()"><pre class="notranslate"><code class="notranslate">#!div style="font-size: 80%"
Code highlighting:
  `#!python
  session.query(User).filter(or_(expression.false(), expression.true())).all()
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2013-09-15 23:40:11,761 INFO sqlalchemy.engine.base.Engine SELECT [user](user).id AS user_id, [user](user).name AS user_name 
FROM [user](user) 
WHERE 0 OR 1
2013-09-15 23:40:11,761 INFO sqlalchemy.engine.base.Engine ()
Traceback (most recent call last):
  File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py&quot;, line 2249, in all
    return list(self)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py&quot;, line 2361, in __iter__
    return self._execute_and_instances(context)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py&quot;, line 2376, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py&quot;, line 661, in execute
    params)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py&quot;, line 762, in _execute_clauseelement
    compiled_sql, distilled_params
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py&quot;, line 875, in _execute_context
    context)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py&quot;, line 1019, in _handle_dbapi_exception
    exc_info
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\util\compat.py&quot;, line 197, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\util\compat.py&quot;, line 190, in reraise
    raise value.with_traceback(tb)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py&quot;, line 868, in _execute_context
    context)
  File &quot;C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\default.py&quot;, line 372, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', &quot;[42000](42000) [Microsoft](Microsoft)[SQL Server Driver](ODBC)[Server](SQL)An expression of non-boolean type specified in a context where a condition is expected, near 'OR'. (4145) (SQLExecDirectW)&quot;) 'SELECT [user](user).id AS user_id, [user](user).name AS user_name \nFROM [user](user) \nWHERE 0 OR 1' ()"><pre class="notranslate"><code class="notranslate">2013-09-15 23:40:11,761 INFO sqlalchemy.engine.base.Engine SELECT [user](user).id AS user_id, [user](user).name AS user_name 
FROM [user](user) 
WHERE 0 OR 1
2013-09-15 23:40:11,761 INFO sqlalchemy.engine.base.Engine ()
Traceback (most recent call last):
  File "&lt;console&gt;", line 1, in &lt;module&gt;
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py", line 2249, in all
    return list(self)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py", line 2361, in __iter__
    return self._execute_and_instances(context)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\orm\query.py", line 2376, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py", line 661, in execute
    params)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py", line 762, in _execute_clauseelement
    compiled_sql, distilled_params
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py", line 875, in _execute_context
    context)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py", line 1019, in _handle_dbapi_exception
    exc_info
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\util\compat.py", line 197, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\util\compat.py", line 190, in reraise
    raise value.with_traceback(tb)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\base.py", line 868, in _execute_context
    context)
  File "C:\Python33\lib\site-packages\sqlalchemy-0.9.0dev-py3.3-win-amd64.egg\sqlalchemy\engine\default.py", line 372, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000](42000) [Microsoft](Microsoft)[SQL Server Driver](ODBC)[Server](SQL)An expression of non-boolean type specified in a context where a condition is expected, near 'OR'. (4145) (SQLExecDirectW)") 'SELECT [user](user).id AS user_id, [user](user).name AS user_name \nFROM [user](user) \nWHERE 0 OR 1' ()
</code></pre></div>