CompileError with column named "<tablename>_<id>"

Issue #1755 resolved
Former user created an issue

I've confirmed this works as expected on 0.5.8, however it is broken on in (at least) 0.6beta2 and 0.6beta3.

Naming a column within a table as {{{<table>_<id>}}} causes SQLAlchemy to fail when attempting to update the object. I've attached a script using a SQLite memory database that can replicate the issue.

Example:

class Book(Base):
    __tablename__ = 'book'

    id = Column(Integer, primary_key=True)
    book_id = Column(String(36), unique=True, nullable=False)
    title = Column(String(128), nullable=False)

s = Session()
book = Book(book_id=str(uuid4()), title='1984')
s.add(book)
s.commit()

book.title = 'Brave New World'
s.commit()

This will provide the following traceback on the 2nd commit:

...
  File "/Users/michael/virtualenv/paste/lib/python2.6/site-packages/SQLAlchemy-0.6beta3-py2.6.egg/sqlalchemy/engine/base.py", line 676, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/Users/michael/virtualenv/paste/lib/python2.6/site-packages/SQLAlchemy-0.6beta3-py2.6.egg/sqlalchemy/sql/visitors.py", line 47, in _compiler_dispatch
    return getter(visitor)(self, **kw)
  File "/Users/michael/virtualenv/paste/lib/python2.6/site-packages/SQLAlchemy-0.6beta3-py2.6.egg/sqlalchemy/sql/compiler.py", line 553, in visit_bindparam
    % bindparam.key
sqlalchemy.exc.CompileError: Bind parameter name 'book_id' is reserved for the VALUES or SET clause of this insert/update statement.

Comments (2)

  1. Log in to comment