[Sqlalchemy-tickets] Issue #3305: Backend-agnostic GUID breaks session tracking (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Wichert A. <iss...@bi...> - 2015-02-10 15:17:25
|
New issue 3305: Backend-agnostic GUID breaks session tracking https://bitbucket.org/zzzeek/sqlalchemy/issue/3305/backend-agnostic-guid-breaks-session Wichert Akkerman: I have a PostgreSQL database which uses a UUID column as primary key. To access this via SQLAlchemy and still allow testing with SQLite I am using the [http://docs.sqlalchemy.org/en/rel_0_9/core/custom_types.html#backend-agnostic-guid-type](Backend-agnostic GUID type) from the documentation. With this model I notice something strange: cached objects merged into the session still trigger SELECTs when they are accessed. I have attached an example which shows this: it sets up two tables with a simple parent/child relationship, creates some data, pickles and unpickles that to simulate a cache and finally access child objects through the relationship. If I use an Integer type for the primary keys this works as expected and no SELECTs are generated. Using the GUID type I see the following: ``` Accessing children. This should not trigger any SQL statements 2015-02-10 16:06:53,997 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) 2015-02-10 16:06:53,998 INFO sqlalchemy.engine.base.Engine SELECT child.id AS child_id, child.parent_id AS child_parent_id, child.name AS child_name FROM child WHERE ? = child.parent_id 2015-02-10 16:06:53,998 INFO sqlalchemy.engine.base.Engine ('7de83a91-1b08-4d8e-808b-cc9d91fe2491',) [u'child-1', u'child-2', u'child-3'] 2015-02-10 16:06:53,998 INFO sqlalchemy.engine.base.Engine ROLLBACK ``` |