using conv() should be bypassing naming convention entirely

Issue #3068 duplicate
Mike Bayer repo owner created an issue

this issue is mostly fixed by c33d0378802a with #3028 but that is a different issue being fixed here. if conv() is present we shouldn't be hitting naming convention logic at all. the below fails in 0.9.4 but succeeds in rel_0_9:

from sqlalchemy import UniqueConstraint, Table, MetaData
from sqlalchemy.sql.naming import conv

m = MetaData(naming_convention={"uq": "uq_%(table_name)s_%(column_0_name)s"})

t = Table('mytable', m)
uq = UniqueConstraint(name=conv('my_special_key'))

t.append_constraint(uq)

Comments (9)

  1. Mike Bayer reporter

    this still fails on latest:

    from sqlalchemy import UniqueConstraint, Table, MetaData
    from sqlalchemy.sql.naming import conv
    
    m = MetaData(naming_convention={"uq": "uq_%(constraint_name)s_%(column_0_name)s"})
    
    t = Table('mytable', m)
    uq = UniqueConstraint(name=conv('my_special_key'))
    
    t.append_constraint(uq)
    
  2. Mike Bayer reporter

    here's a simple patch:

    index 34a72a0..7ac3e96 100644
    --- a/lib/sqlalchemy/sql/naming.py
    +++ b/lib/sqlalchemy/sql/naming.py
    @@ -158,7 +158,9 @@ def _constraint_name(const, table):
             metadata = table.metadata
             convention = _get_convention(metadata.naming_convention, type(const))
             if convention is not None:
    -            if const.name is None or "constraint_name" in convention:
    +            if not isinstance(const.name, conv) and (
    +                    const.name is None or "constraint_name" in convention
    +                ):
                     newname = conv(
                                 convention % ConventionDict(const, table, metadata.naming_convention)
                                 )
    
  3. Log in to comment