PG column names with both % and . do not work
For some unknown reason, when you create a declarative class, and use the orm to access it, if you have multiple characters in need of escaping, the dot_operator does not work on the result instance. In the example below, if your remove either the "%" or the "." betweeen "weird" and "column", r.bad_column returns just fine.
from sqlalchemy import MetaData, Column, String, Integer, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('postgresql+psycopg2://localhost/test_pg_column_bug')
metadata = MetaData(bind=engine)
DeclarativeBase = declarative_base(metadata=metadata)
session = sessionmaker(bind=engine)()
metadata.drop_all()
class BadTable(DeclarativeBase):
__tablename__ = 'bad_table'
id = Column(Integer(), primary_key=True)
bad_column = Column(String(), name='weird . % column')
metadata.create_all()
r = BadTable(bad_column=1200.0)
session.add(r)
session.flush()
session.commit()
r = session.query(BadTable).first()
print 'dot op: ', r.bad_column
cheers. -chris (percious)
Comments (4)
-
Account Deleted -
repo owner works fine in 0.7 thanks to 8e24584d8d242d40d605752116ac05be33f697d3
also don't let your DBA see you using column names with spaces and punctuation characters in them
-
Account Deleted Replying to zzzeek:
works fine in 0.7 thanks to 8e24584d8d242d40d605752116ac05be33f697d3
also don't let your DBA see you using column names with spaces and punctuation characters in them
Unfortunately I don't have control of the DB schema.
Thanks. -chris
-
repo owner - removed milestone
Removing milestone: 0.7.0 (automated comment)
- Log in to comment
I just verified this happens in sqlite as well.