Hi!

Here is a small (and not very useful) example to demonstrate the
problem. A table "user" contains a reference to itself (so that I
don't need a second table). This foreign key translates to a relation.
When I compare the corresponding attribute to null(), I get a
traceback. It all works if I compare it to None instead.


from sqlalchemy.engine import create_engine
from sqlalchemy.schema import MetaData, Table, Column, ForeignKey
from sqlalchemy.types import Integer
from sqlalchemy.orm import mapper, relation, create_session
from sqlalchemy.sql import null

engine = create_engine("postgres://...")
metadata = MetaData(engine)

user = Table("user", metadata,
             Column("id", Integer, nullable=False, primary_key=True),
             Column("fk", Integer, ForeignKey("public.user.id")),
             schema="public", useexisting=True, autoload=False)

class User(object):
    pass

mapper(User, user, properties={"ref": relation(User, uselist=False)})

metadata.create_all()

session = create_session()

print session.query(User).filter(User.ref == null()).all()

metadata.drop_all()


(The last line is not executed.)

Here's the traceback:


Traceback (most recent call last):
  File "sqlatest.py", line 24, in ?
    print session.query(User).filter(User.ref == null()).all()
  File "/home/barthelmannk/PortaleHeadZope/sandbox/eggs/
SQLAlchemy-0.5.4p1-py2.4.egg/sqlalchemy/sql/expression.py", line 1253,
in __eq__
    return self.operate(operators.eq, other)
  File "/home/barthelmannk/PortaleHeadZope/sandbox/eggs/
SQLAlchemy-0.5.4p1-py2.4.egg/sqlalchemy/orm/attributes.py", line 120,
in operate
    return op(self.comparator, *other, **kwargs)
  File "/home/barthelmannk/PortaleHeadZope/sandbox/eggs/
SQLAlchemy-0.5.4p1-py2.4.egg/sqlalchemy/orm/properties.py", line 492,
in __eq__
    return _orm_annotate(self.property._optimized_compare(other,
adapt_source=self.adapter))
  File "/home/barthelmannk/PortaleHeadZope/sandbox/eggs/
SQLAlchemy-0.5.4p1-py2.4.egg/sqlalchemy/orm/properties.py", line 623,
in _optimized_compare
    value = attributes.instance_state(value)
AttributeError: '_Null' object has no attribute '_sa_instance_state'


Cheers
Klaus

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to