Column.copy() with enum no longer sends create events

Issue #3827 resolved
Grzegorz Śliwiński created an issue
from sqlalchemy import *
from sqlalchemy.orm import *

m = MetaData()

y = Column('y', Enum('a', 'b', 'c', name='myenum'))

t = Table(
    'x', m,
    y.copy()
)

e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)

c = e.connect()
t = c.begin()

m.create_all(c)

output:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) type "myenum" does not exist
LINE 3:  y myenum
           ^
 [SQL: '\nCREATE TABLE x (\n\ty myenum\n)\n\n']

this is a regression vs. 1.0 and in particular affects various declarative mechamisms such as mixins.

Comments (4)

  1. Mike Bayer repo owner

    Add explicit copy() to Enum

    The Boolean and Enum types both place SchemaType second in the inheritance hierarchy. In the case of Enum, this works out that the copy() method is called from the base TypeEngine which fails to transfer _create_events. The test suite doesn't seem to work with the inhertance hierarchy set up like this as the event listeners don't work out, the _on_metadata_create and _on_table_create hooks cause the production of an adapted type which then adds event listeners that cause deque changed while iteration. It's not clear why Enum /Boolean don't have this problem. But in any case it seems like the class mechanics for these types remains fragile and would benefit from yet another refactor someday.

    Change-Id: Ib641a5d2321b00f58bbe98dd0c5e789374db32b2 Fixes: #3827

    → <<cset 8ef4f6a53864>>

  2. Log in to comment