[Sqlalchemy-tickets] Issue #3299: schematype constraints don't use naming convention if it doesnt i
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-01-30 17:20:09
|
New issue 3299: schematype constraints don't use naming convention if it doesnt include "constraint_name" https://bitbucket.org/zzzeek/sqlalchemy/issue/3299/schematype-constraints-dont-use-naming Mike Bayer: this is a little limiting. due to #3067, the constraint convention below will not even be consulted: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base m1 = MetaData(naming_convention={"ck": "ck_%(table_name)s_%(column_0_name)s"}) Base = declarative_base(metadata=m1) class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) foob = Column(BOOLEAN) e = create_engine("mysql://scott:tiger@localhost/test", echo=True) Base.metadata.drop_all(e) Base.metadata.create_all(e) ``` this change needs to be made in order for it to be seen: ``` #!diff diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py index 9e57418..21bf05d 100644 --- a/lib/sqlalchemy/sql/naming.py +++ b/lib/sqlalchemy/sql/naming.py @@ -114,8 +114,9 @@ def _constraint_name_for_table(const, table): if isinstance(const.name, conv): return const.name elif convention is not None and ( - const.name is None or not isinstance(const.name, conv) and - "constraint_name" in convention + const.name is None or ( + not isinstance(const.name, conv) or + "constraint_name" in convention) ): return conv( convention % ConventionDict(const, table, ``` there's no reason CheckConstraint can't have a .columns collection so that the columns_0_name convention can be useful. I dont know that we want to change this for 0.9. |