- changed status to resolved
allow StrSQLCompiler to generate columns w/o names
Issue #3789
resolved
e.g. for this:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
a_id = Column(Integer)
class AbstractThing(Base):
__abstract__ = True
id = Column(Integer, primary_key=True)
class A(AbstractThing):
__tablename__ = 'a'
bs = relationship("B", primaryjoin=B.a_id == AbstractThing.id)
configure_mappers()
patch:
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 85d5ff6..38013fb 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -660,12 +660,15 @@ class SQLCompiler(Compiled):
return label.element._compiler_dispatch(
self, within_columns_clause=False, **kw)
+ def _fallback_column_name(self, column):
+ raise exc.CompileError("Cannot compile Column object until "
+ "its 'name' is assigned.")
+
def visit_column(self, column, add_to_result_map=None,
include_table=True, **kwargs):
name = orig_name = column.name
if name is None:
- raise exc.CompileError("Cannot compile Column object until "
- "its 'name' is assigned.")
+ name = self._fallback_column_name(column)
is_literal = column.is_literal
if not is_literal and isinstance(name, elements._truncated_label):
@@ -2203,6 +2206,9 @@ class StrSQLCompiler(SQLCompiler):
"""
+ def _fallback_column_name(self, column):
+ return "<name unknown>"
+
def visit_getitem_binary(self, binary, operator, **kw):
return "%s[%s]" % (
self.process(binary.left, **kw),
Comments (1)
-
reporter - Log in to comment
Allow stringify compiler to render unnamed column
Stringify of expression with unnamed :class:
.Column
objects, as occurs in lots of situations including ORM error reporting, will now render the name in string context as "<name unknown>" rather than raising a compile error.Change-Id: I76f637c5eb4cfdb1b526964cb001565b97e296da Fixes:
#3789→ <<cset 9a6947427af5>>