On Wed, 22 Jan 2014 16:45:19 -0800, Ryan Ollos <[email protected]> wrote :
> On Wed, Jan 22, 2014 at 4:27 PM, Saint Germain <[email protected]> > wrote: > > > On Mon, 20 Jan 2014 00:10:55 -0500, Olemis Lang <[email protected]> > > wrote : > > > > > > > > > > Currently on trunk I got a lot of similar mistakes when running > > > > the test on bloodhound_search like this one: > > > > > > > > ====================================================================== > > > > ERROR: test_admin_granted_in_product_should_not_have_access > > > > (bhsearch.tests.security.MultiProductSecurityTestCase) > > > > ---------------------------------------------------------------------- > > > > Traceback (most recent call last): > > > [...] > > > > OperationalError: duplicate column name: product > > > > > > > > Does that ring a bell to someone ? > > > > > > > > > > It looks ok to me , see http://pastebin.com/kxvua4TU > > > > > > > Hello ! > > > > I found the problem. > > > > In tests/env.py we have: > > from sqlite3 import OperationalError > > > > And in trac/trac/db/sqlite_backend.py we have: > > try: > > import pysqlite2.dbapi2 as sqlite > > have_pysqlite = 2 > > except ImportError: > > try: > > import sqlite3 as sqlite > > have_pysqlite = 2 > > except ImportError: > > have_pysqlite = 0 > > > > As I have both sqlite3 and python-pysqlite2 installed, I got a > > mismatch when an exception is raised: > > sqlite3.OperationalError != pysqlite2.dbapi2.OperationalError > > > > And the tests cannot run. > > > > If I deinstall python-pysqlite2, then the tests can run. > > > > Do you think it is necessary to fix this ? > > In test files we can reproduce the same logic as in the > > sqlite_backend to correctly import sqlite. > > > > Best regards, > > > > > Trac provides an API for working with database exceptions. I believe > the following patch would be the proper way to handle it. Would you > kindly test it in your environment? > > diff --git a/bloodhound_multiproduct/tests/env.py > b/bloodhound_multiproduct/tests/env.py > index 30910e4..98cd1bc 100644 > --- a/bloodhound_multiproduct/tests/env.py > +++ b/bloodhound_multiproduct/tests/env.py > @@ -23,7 +23,6 @@ from inspect import stack > import os.path > import shutil > import tempfile > -from sqlite3 import OperationalError > from tests import unittest > from types import MethodType > > @@ -230,7 +229,7 @@ class MultiproductTestCase(unittest.TestCase): > mpsystem = MultiProductSystem(env) > try: > mpsystem.upgrade_environment(env.db_transaction) > - except OperationalError: > + except env.db_exc.OperationalError: > # Database is upgraded, but database version was deleted. > # Complete the upgrade by inserting default product. > mpsystem._insert_default_product(env.db_transaction) Hello ! Thanks for the patch. I had to propagate the change in order to run all the tests. So I suppose that the final patch for this problem is the following: diff -r 28dff22568f4 bloodhound_multiproduct/multiproduct/env.py --- a/bloodhound_multiproduct/multiproduct/env.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_multiproduct/multiproduct/env.py Thu Jan 23 02:20:30 2014 +0100 @@ -21,7 +21,6 @@ import os.path from urlparse import urlsplit -from sqlite3 import OperationalError from trac.config import BoolOption, ConfigSection, Option from trac.core import Component, ComponentManager, ExtensionPoint, implements, \ diff -r 28dff22568f4 bloodhound_multiproduct/tests/env.py --- a/bloodhound_multiproduct/tests/env.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_multiproduct/tests/env.py Thu Jan 23 02:20:30 2014 +0100 @@ -23,7 +23,6 @@ import os.path import shutil import tempfile -from sqlite3 import OperationalError from tests import unittest from types import MethodType @@ -230,7 +229,7 @@ mpsystem = MultiProductSystem(env) try: mpsystem.upgrade_environment(env.db_transaction) - except OperationalError: + except env.db_exc.OperationalError: # Database is upgraded, but database version was deleted. # Complete the upgrade by inserting default product. mpsystem._insert_default_product(env.db_transaction) @@ -310,7 +309,7 @@ if self.env is not None: try: self.env.reset_db() - except OperationalError: + except self.env.db_exc.OperationalError: # "Database not found ...", # "OperationalError: no such table: system" or the like pass @@ -575,7 +574,7 @@ if self.env is not None: try: self.env.reset_db() - except OperationalError: + except self.env.db_exc.OperationalError: # "Database not found ...", # "OperationalError: no such table: system" or the like pass diff -r 28dff22568f4 bloodhound_multiproduct/tests/model.py --- a/bloodhound_multiproduct/tests/model.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_multiproduct/tests/model.py Thu Jan 23 02:20:30 2014 +0100 @@ -19,7 +19,6 @@ """Tests for multiproduct/model.py""" import shutil import tempfile -from sqlite3 import OperationalError from tests import unittest from trac.core import TracError @@ -46,7 +45,7 @@ self.mpsystem = MultiProductSystem(self.env) try: self.mpsystem.upgrade_environment(self.env.db_transaction) - except OperationalError: + except self.env.db_exc.OperationalError: # table remains but database version is deleted pass diff -r 28dff22568f4 bloodhound_multiproduct/tests/upgrade.py --- a/bloodhound_multiproduct/tests/upgrade.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_multiproduct/tests/upgrade.py Thu Jan 23 02:20:30 2014 +0100 @@ -21,7 +21,6 @@ import shutil import tempfile import uuid -from sqlite3 import OperationalError from contextlib import contextmanager from tests import unittest @@ -434,13 +433,13 @@ @contextmanager def assertFailsWithMissingTable(self): - with self.assertRaises(OperationalError) as cm: + with self.assertRaises(self.env.db_exc.OperationalError) as cm: yield self.assertIn('no such table', str(cm.exception)) @contextmanager def assertFailsWithMissingColumn(self): - with self.assertRaises(OperationalError) as cm: + with self.assertRaises(self.env.db_exc.OperationalError) as cm: yield self.assertIn('no such column', str(cm.exception)) diff -r 28dff22568f4 bloodhound_relations/bhrelations/search.py --- a/bloodhound_relations/bhrelations/search.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_relations/bhrelations/search.py Thu Jan 23 02:20:30 2014 +0100 @@ -18,8 +18,6 @@ # specific language governing permissions and limitations # under the License. -from sqlite3 import OperationalError - from trac.core import Component, implements from bhsearch.api import IDocIndexPreprocessor @@ -42,7 +40,7 @@ for relation in rls._select_relations(resource_id): relations.extend(self._format_relations(relation)) doc['relations'] = ','.join(relations) - except OperationalError: + except self.env.db_exc.OperationalError: # If bhrelations and bhsearch are installed at the same time and # bhsearch is upgraded before bhrelations, table # bloodhound_relations will be missing, thus causing the diff -r 28dff22568f4 bloodhound_relations/bhrelations/tests/api.py --- a/bloodhound_relations/bhrelations/tests/api.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_relations/bhrelations/tests/api.py Thu Jan 23 02:20:30 2014 +0100 @@ -18,7 +18,6 @@ # specific language governing permissions and limitations # under the License. from datetime import datetime -from _sqlite3 import IntegrityError import unittest from bhrelations.api import TicketRelationsSpecifics from bhrelations.tests.mocks import TestRelationChangingListener @@ -98,7 +97,10 @@ with self.env.db_transaction as db: db(sql, ["1", "2", "dependson"]) self.assertRaises( - IntegrityError, db, sql, ["1", "2", "dependson"]) + self.env.db_exc.IntegrityError, + db, + sql, + ["1", "2", "dependson"]) def test_can_add_one_way_relations(self): #arrange diff -r 28dff22568f4 bloodhound_relations/bhrelations/tests/base.py --- a/bloodhound_relations/bhrelations/tests/base.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_relations/bhrelations/tests/base.py Thu Jan 23 02:20:30 2014 +0100 @@ -15,7 +15,6 @@ # specific language governing permissions and limitations # under the License. -from _sqlite3 import OperationalError from tests.env import MultiproductTestCase from multiproduct.env import ProductEnvironment from bhrelations.api import RelationsSystem, EnvironmentSetup, \ @@ -86,7 +85,7 @@ environment_setup = EnvironmentSetup(self.env) try: environment_setup.upgrade_environment(self.env.db_transaction) - except OperationalError: + except self.env.db_exc.OperationalError: # table remains but database version is deleted pass diff -r 28dff22568f4 bloodhound_search/bhsearch/tests/security.py --- a/bloodhound_search/bhsearch/tests/security.py Thu Jan 23 00:29:55 2014 +0100 +++ b/bloodhound_search/bhsearch/tests/security.py Thu Jan 23 02:20:30 2014 +0100 @@ -24,7 +24,6 @@ """ import contextlib import os -from sqlite3 import OperationalError from bhsearch.security import SecurityFilter try: @@ -69,7 +68,7 @@ try: MultiProductSystem(self.env)\ .upgrade_environment(self.env.db_transaction) - except OperationalError: + except self.env.db_exc.OperationalError: # table remains but content is deleted self._add_products('@') self.env.enable_multiproduct_schema()
