I was looking at using a UUID as primary key for a table. Using the 
backend-agnostic GUID type from 
http://docs.sqlalchemy.org/en/rel_0_8/core/types.html#backend-agnostic-guid-type
 I get strange behaviour though. I whipped up a simple test case:


class Data(BaseObject):
    __tablename__ = 'data'
    uuid = Column(GUID(), primary_key=True)
                
            
metadata.create_all()
session = sessionmaker(autocommit=False)()

uuid = 'ac4daeff-3af3-4b83-b8c7-3aa34e34151c'
obj = Data(uuid=uuid)
session.add(obj)
assert session.query(Data).get(uuid) is obj
assert session.query(Data).filter(Data.uuid == uuid).first()  is obj

Both asserts fail when I do this. The problem appears to be conversion from to 
a uuid.UUID instance in GUID.process_result_value: this always creates a new 
UUID instance, which probably causes a miss when SQLAlchemy tries to find an 
instance in its identify map.

Is this a bug in the GUID example in the documentation, or is this something 
that can be improved in the identity map?

Wichert.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to