warn on ambiguous naming convention case
from https://bitbucket.org/zzzeek/alembic/issues/453, there are five possibilities when rendering the name of a constraint:
-
if the constraint has a name of
None
, then the naming convention is applied. -
if the constraint name has a name of
None
, and the naming convention includes the token%(constraint_name)s
, then an error is raised: "Naming convention including %(constraint_name)s token requires that constraint is explicitly named." -
if the constraint has a non-
None
name, and the convention does not include the%(constraint_name)s
token, then it is assumed that the constraint was given an explicit name, and the convention is not applied. -
if the constraint has a non-
None
name, and the convention includes the token%(constraint_name)s
, then it is assumed that this name is part of fulfillment of the contract of the convention, and the naming convention is applied, using the existing name for%(constraint_name)s
. -
if the constraint has an
f()
name, then no naming convention is applied ever.
Case #3 is ambiguous.
propose a warning as:
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index d93c916f6..1cf1e77ae 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -125,6 +125,12 @@ def _constraint_name_for_table(const, table):
)
elif isinstance(convention, _defer_none_name):
return None
+ elif convention is not None and const.name is not None:
+ from sqlalchemy import util
+ util.warn(
+ "Ambiguous naming behavior for name '%s' on %r object; "
+ "naming convention not being applied but name does not make "
+ "use of f()" % (const.name, type(const)))
@event.listens_for(Constraint, "after_parent_attach")
Comments (2)
-
reporter -
reporter - changed milestone to 1.3
- Log in to comment
https://gerrit.sqlalchemy.org/519 this might be a 1.3 thing because the documentation burden is large.