1. Michael Bayer
  2. sqlalchemy
  3. Issues

Issues

Issue #127 resolved

bindparam name generated by relation too long

Anonymous created an issue

When having two tables, one of them has a foreign key to the other, and you define a relation between the tables, the automatically generated bindparam name can get too long. Example below:

from sqlalchemy import *

engine = create_engine('oracle://dsn=orcl&user=test&password=test')

foo = Table('some_table_name', engine,
    Column('id', Integer, Sequence('foo_seq'), primary_key=True))
bar = Table('another_table', engine,
    Column('id', Integer, Sequence('bar_seq'), primary_key=True),
    Column('some_table_name_id', Integer, ForeignKey('some_table_name.id')))

class Foo(object): pass
class Bar(object): pass

foos = mapper(Foo, foo)
bars = mapper(Bar, bar)
foos.add_property('bars', relation(bars))

tables = foo, bar

for table in reversed(tables):
    try: table.drop()
    except Exception, e: print e

for table in tables:
    try: table.create()
    except Exception, e: print e

foo.insert().execute()

for b in foos.selectfirst().bars:
    print b

This is the exception:

Traceback (most recent call last):
  File "longname.py", line 30, in ?
    for b in foos.selectfirst().bars:
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/attributes.py", line 51, in __get__
    return self.manager.get_list_attribute(obj, self.key)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/attributes.py", line 304, in get_list_attribute
    return self.get_history(obj, key, **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/attributes.py", line 367, in get_history
    return self.class_managed(obj.__class__)[key](key)(obj, **kwargs).gethistory(passive=passive, **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/attributes.py", line 223, in gethistory
    value = self.callable_()
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/mapping/properties.py", line 600, in lazyload
    result = self.mapper.select(self.lazywhere, order_by=order_by, params=params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/mapping/mapper.py", line 511, in select
    return self.select_whereclause(arg, **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/mapping/mapper.py", line 515, in select_whereclause
    return self._select_statement(statement, params=params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/mapping/mapper.py", line 535, in _select_statement
    return self.instances(statement.execute(**params), **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/sql.py", line 436, in execute
    return c.execute(*multiparams, **params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/sql.py", line 330, in execute
    return self.engine.execute_compiled(self, params)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/engine.py", line 643, in execute_compiled
    proxy(str(compiled), parameters)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/engine.py", line 638, in proxy
    self.execute(statement, parameters, connection=connection, cursor=cursor, return_raw=True)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/engine.py", line 689, in execute
    self._execute(cursor, statement, parameters)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.1.4-py2.4.egg/sqlalchemy/engine.py", line 709, in _execute
    raise exceptions.SQLError(statement, parameters, e)
sqlalchemy.exceptions.SQLError: (DatabaseError) ORA-00972: identifier is too long
 'SELECT another_table.some_table_name_id AS another_table_some_table_1df3, another_table.id AS another_table_id \nFROM another_table \nWHERE another_table.some_table_name_id = :another_table_some_table_name_id' {'another_table_some_table_name_id': 1}

Comments (2)

  1. Michael Bayer repo owner

    this all should be fixed in changeset:1207.

    removed all "tablename + '_' + columname" code and replaced with column._label, to take advantage of column labeling rules

    bind param compilation,when it unique-ifys the name of bind params, maintains the length of the bind parameter name instead of appending to it

  2. Log in to comment