diff --git a/tests/store/base.py b/tests/store/base.py index 541b633..fc61945 100644 --- a/tests/store/base.py +++ b/tests/store/base.py @@ -27,6 +27,7 @@ import operator from uuid import uuid4 import weakref +from storm.base import Storm from storm.references import Reference, ReferenceSet, Proxy from storm.database import Result, STATE_DISCONNECTED from storm.properties import ( @@ -131,6 +132,20 @@ class Money(object): value = Decimal() +class Customer(Storm): + __storm_table__ = 'customer' + id = Int(primary=True) + email = Unicode() + tag = Unicode() + + +class Purchase(Storm): + __storm_table__ = 'purchase' + id = Int(primary=True) + custid = Unicode() + customer = Reference(custid, Customer.email) + + class DecorateVariable(Variable): def parse_get(self, value, to_db): @@ -267,7 +282,7 @@ class StoreTest(object): def drop_tables(self): for table in ["foo", "bar", "bin", "link", "money", "selfref", - "foovalue", "unique_id"]: + "foovalue", "unique_id", "customer", "purchase"]: try: self.connection.execute("DROP TABLE %s" % table) self.connection.commit() @@ -466,6 +481,27 @@ class StoreTest(object): self.store.flush() self.assertEquals(self.store._event._hooks["flush"], set()) + def test_flush_on_unicode_reference(self): + """ + Fix for bug 1334020 in which a KeyError is sometimes raised. + """ + def runScenario(store, email): + customer = store.add(Customer()) + customer.email = email + store.commit() + + purchase = store.add(Purchase()) + purchase.customer = customer + + store.commit() + + customer = store.find(Customer, Customer.email == email).one() + customer = list(store.find(Customer)) + + runScenario(self.store, u'foo@foo.com') + runScenario(self.store, u'bar@bar.com') + + def test_mutable_variable_detect_change_from_alive(self): """ Changes in a mutable variable like a L{PickleVariable} are correctly diff --git a/tests/store/mysql.py b/tests/store/mysql.py index c90b25b..7a33559 100644 --- a/tests/store/mysql.py +++ b/tests/store/mysql.py @@ -79,6 +79,15 @@ class MySQLStoreTest(TestHelper, StoreTest): connection.execute("CREATE TABLE unique_id " "(id VARCHAR(36) PRIMARY KEY) " "ENGINE=InnoDB") + connection.execute("CREATE TABLE customer (" + "email VARCHAR(50) NOT NULL, " + "id INT PRIMARY KEY AUTO_INCREMENT, " + "tag VARCHAR(50)) " + "ENGINE=InnoDB") + connection.execute("CREATE TABLE purchase (" + "id INT PRIMARY KEY AUTO_INCREMENT, " + "custid VARCHAR(50)) " + "ENGINE=InnoDB") connection.commit() diff --git a/tests/store/postgres.py b/tests/store/postgres.py index c9ce63e..cdf2788 100644 --- a/tests/store/postgres.py +++ b/tests/store/postgres.py @@ -93,6 +93,13 @@ class PostgresStoreTest(TestHelper, StoreTest): " value1 INTEGER, value2 INTEGER)") connection.execute("CREATE TABLE unique_id " "(id UUID PRIMARY KEY)") + connection.execute("CREATE TABLE customer (" + "email TEXT NOT NULL, " + "id SERIAL PRIMARY KEY, " + "tag TEXT)") + connection.execute("CREATE TABLE purchase (" + "id SERIAL PRIMARY KEY, " + "custid TEXT)") connection.commit() def drop_tables(self): diff --git a/tests/store/sqlite.py b/tests/store/sqlite.py index 51fcc51..9315a8e 100644 --- a/tests/store/sqlite.py +++ b/tests/store/sqlite.py @@ -65,6 +65,13 @@ class SQLiteStoreTest(TestHelper, StoreTest): " value1 INTEGER, value2 INTEGER)") connection.execute("CREATE TABLE unique_id " "(id VARCHAR PRIMARY KEY)") + connection.execute("CREATE TABLE customer (" + "email TEXT NOT NULL, " + "id INTEGER PRIMARY KEY, " + "tag TEXT)") + connection.execute("CREATE TABLE purchase (" + "id INTEGER PRIMARY KEY, " + "custid TEXT)") connection.commit() def drop_tables(self):