PG column names with both % and . do not work

Issue #2043 resolved
Former user created an issue

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)

  1. Log in to comment