pk bindparam expressions busted when constructing joins

Issue #768 resolved
Mike Bayer repo owner created an issue
Hi,
I have the following two tables (in MySql):

CREATE TABLE `A` (
  `xkey` varchar(200) NOT NULL,
  `yval` int(11) default NULL,
  PRIMARY KEY  (`xkey`)
) ENGINE=InnoDB;

and

CREATE TABLE `B` (
  `xkey` varchar(200) NOT NULL default '',
  `s` enum('yes','no') NOT NULL default 'yes',
  PRIMARY KEY  (`xkey`,`s`)
) ENGINE=InnoDB;

The following statement worked fine till 0.3.8 , and from 0.3.9 throws
the exception:

oj=outerjoin(A, B,  and_(A.c.xkey==B.c.xkey, B.c.s=='yes'))


Traceback (most recent call last):
  File "join.py", line 13, in ?
    oj=outerjoin(A, B,  and_(A.c.xkey==B.c.xkey, B.c.s=='yes'))
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.9-
py2.4.egg/sqlalchemy/sql.py", line 117, in outerjoin
    return Join(left, right, onclause, isouter = True, **kwargs)
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.9-
py2.4.egg/sqlalchemy/sql.py", line 2256, in __init__
    self._init_primary_key()
  File "/usr/local/lib/python2.4/site-packages/SQLAlchemy-0.3.9-
py2.4.egg/sqlalchemy/sql.py", line 2287, in _init_primary_key
    if p.references(c) or (c.primary_key and not p.primary_key):
AttributeError: '_BindParamClause' object has no attribute
'primary_key'


Note, if B.s were not an enum but a varchar, it would have worked.

Comments (6)

  1. Mike Bayer reporter

    i see the issue here (just do a getattr instead of x.primary_key), but how come changing from "enum" to "varchar" works ? is that not the case ?

  2. jek

    It's not the case. It doesn't matter what the type of the column is, so long as it's a member of the primary key.

  3. Log in to comment