- changed milestone to 0.8.xx
- changed component to declarative
- changed title to emit warning when Column is assigned directly to multiple names
emit warning when Column is assigned directly to multiple names
Issue #2828
resolved
column_property hides original column from mapper when used with no change.
Results from running the attached column_property.py, tested against sqlalchemy git clone just now --
(sqlalchemy) C:\sqlalchemy>ipython
Python 2.7.5 (default, May 15 2013, 22:44:16) [v.1500 64 bit (AMD64)](MSC)
In [1](1): import sqlalchemy
In [2](2): sqlalchemy.__version__
Out[2](2): '0.9.0'
In [3](3): %run column_property.py
['id']('name_alias',)
['id', 'name']('name_alias',)
column_property.py (in case attachment fails), maybe not the right way to create an aliasing column, but still looks like a bug to me --
from sqlalchemy import (
create_engine,
Column,
Text,
Integer,
)
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
column_property,
)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class NameMissing(Base):
__tablename__ = 'name_missing'
id = Column(Integer, primary_key=True)
name = Column(Text)
name_alias = column_property(name)
def __init__(self, id, name):
self.id = id
self.name = name
class NameOK(Base):
__tablename__ = 'name_ok'
id = Column(Integer, primary_key=True)
name = Column(Text)
name_alias = column_property(name+'')
def __init__(self, id, name):
self.id = id
self.name = name
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
dbsession = scoped_session(sessionmaker(bind=engine))
new_name_missing = NameMissing(1, 'foobar')
dbsession.add(new_name_missing)
new_name_ok = NameOK(1, 'foobar')
dbsession.add(new_name_ok)
dbsession.commit()
name_missing = dbsession.query(NameMissing).first()
print name_missing.__mapper__.columns.keys()
name_ok = dbsession.query(NameOK).first()
print name_ok.__mapper__.columns.keys()
Jerry
Comments (3)
-
repo owner -
repo owner more complete version detects any kind of name collision: de786a4208e621229769a8fb1f876f
-
repo owner - removed milestone
Removing milestone: 0.9.0 (automated comment)
- Log in to comment
there's no bug here, the declaration of
name = Column
is equivalent ofname_alias = column_property(Column)
, and an explicit column property trumps the plain column as you might be passing extra mapping options along. We can emit a warning for when this occurs, this patch is a start, needs some cleanup and tests:this also should probably try to detect if a straight Column is specified multiple times.
in this use case you want to be using synonym in order to produce a straight "alias" of a name.