Opened 10 years ago
Last modified 10 years ago
#11858 new defect
Upgrade failed: table test case already exists
Reported by: | anonymous | Owned by: | Roberto Longobardi |
---|---|---|---|
Priority: | normal | Component: | TestManagerForTracPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.12 |
Description
Hello, i saw this issue already appears before #10849
but there was no real solution.
I try to upgrade from 1.5.1. to 1.8.1
What did i do:
- stop appache webserver
- update to
TracGenericClass-1.1.5-py2.7.egg TracGenericWorkflow-1.0.4-py2.7.egg TestManager-1.8.1-py2.7.egg
- start appache
- hint upgrade required
- stop appache
- trac-admin upgrade
- error: OperationalError: table testcase already exists
Do you have any idea what went wrong? Is there any workaround? (export table, delete table, import table)?
Attachments (0)
Change History (7)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Hi there, sorry for the late answer.
There must be something wrong in the TracGenericClass code that actually performs the upgrade...
I don't think there may be a workround, so I'll try to take a look at this during next weekend.
Ciao, Roberto
comment:3 Changed 10 years ago by
Hi there, I tried the following scenario and was able to upgrade without any error:
- !Install Trac 0.12.5, no apache, sqlite as the DB (Test Manager 1.5.1 wouldn't run on Trac 1.x).
- !Install Test Manager 1.5.1
- Upgrade the DB
- Create some test catalogs, test case and plans.
- !Install Test Manager 1.8.1
- Restart tracd
- Upgrade hint
- Upgrade DB
- Restart tracd
- Browse test catalogs, test case, test plans: everything works fine.
I guess you have a different configuration: apache didn't ever cause any problem, so I guess it may be related to the DB you are using.
Please, could you specify in some more details your environments:
- Operating system (mine is manjaro Linux)
- Python version (mine is 2.7.8)
- Trac version (mine is 0.12.5) and whether you upgraded it from a previous version
- Database (I use sqlite) and version
I would also like to know if you upgraded the Test Manager to 1.5.1 from a previous version, or if yours was a clean installation.
I will also need a debug-enabled Trac log, showing the DB upgrade error in context.
Thanks, ciao. Roberto
comment:4 Changed 10 years ago by
•Operating system =>Windows 7 64bit •Python version => Python 2.7.1 •Trac version =>new installation 0.12.4 •Database =>sqlite 3.7.8 •TM Plugin => should be a clean installation of 1.5.1. I think there was no update before
Extract from logfile:
2014-07-03 13:46:57,306 Trac[env] INFO: -------------------------------- environment startup [Trac 0.12.4] -------------------------------- 2014-07-03 13:46:57,415 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:46:57,415 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:46:57,415 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:46:57,415 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:46:57,415 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:46:57,415 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x06F63890> requires environment upgrade 2014-07-03 13:46:57,415 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x06F63890> requires environment upgrade 2014-07-03 13:46:57,415 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x06F63890> requires environment upgrade 2014-07-03 13:46:57,415 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x06F63890> requires environment upgrade 2014-07-03 13:46:57,415 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x06F63890> requires environment upgrade 2014-07-03 13:49:18,003 Trac[env] INFO: -------------------------------- environment startup [Trac 0.12.4] -------------------------------- 2014-07-03 13:49:18,362 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:49:18,362 Trac[env] WARNING: Component <testmanager.model.TestManagerModelProvider object at 0x033B02B0> requires environment upgrade 2014-07-03 13:49:18,362 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:49:18,362 Trac[model] INFO: Need to create db tables for class 'resourceworkflowstate'. 2014-07-03 13:49:18,831 Trac[env] INFO: testmanager.model.TestManagerModelProvider upgrading... 2014-07-03 13:49:18,831 Trac[model] INFO: Need to create db tables for class 'testcase'. 2014-07-03 13:49:18,831 Trac[model] INFO: Creating DB for class 'testcase'. 2014-07-03 13:49:18,831 Trac[model] INFO: Creating base table testcase... 2014-07-03 13:49:18,861 Trac[console] ERROR: Exception in trac-admin command: Traceback (most recent call last): File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\admin\console.py", line 107, in onecmd rv = cmd.Cmd.onecmd(self, line) or 0 File "C:\TeamServer\Python25\lib\cmd.py", line 218, in onecmd return self.default(line) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\admin\console.py", line 275, in default return cmd_mgr.execute_command(*args) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\admin\api.py", line 124, in execute_command return f(*fargs) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\env.py", line 787, in _do_upgrade self.env.upgrade(backup=no_backup is None) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\env.py", line 527, in upgrade with_transaction(self)(participant.upgrade_environment) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\api.py", line 77, in transaction_wrapper fn(ldb) File "build/bdist.linux-x86_64/egg/testmanager/model.py", line 1010, in upgrade_environment @self.env.with_transaction(db) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\api.py", line 71, in transaction_wrapper fn(db) File "build/bdist.linux-x86_64/egg/testmanager/model.py", line 1016, in do_upgrade_environment create_db_for_realm(self.env, realm, realm_schema, db) File "build/bdist.linux-x86_64/egg/tracgenericclass/model.py", line 1324, in create_db_for_realm @env.with_transaction(db) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\api.py", line 71, in transaction_wrapper fn(db) File "build/bdist.linux-x86_64/egg/tracgenericclass/model.py", line 1343, in do_create_db_for_realm cursor.execute(stmt) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\util.py", line 66, in execute return self.cursor.execute(sql) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\sqlite_backend.py", line 78, in execute result = PyFormatCursor.execute(self, *args) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\sqlite_backend.py", line 56, in execute args or []) File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\db\sqlite_backend.py", line 48, in _rollback_on_error return function(self, *args, **kwargs) OperationalError: table testcase already exists
Thank you, Christian
comment:5 Changed 10 years ago by
Hi Christian, I'm sorry, I couldn't reproduce the problem even with your exact environment.
This is what I did, please let me know what are you doing differently:
1) Reboot with Windows (.... and get mad at it :D ) 2) Upgrade Flash player and a bunch of useless applications.... :-) 3) Install python 2.7.1, using the Windows 64bit MSI installer found here https://www.python.org/download/releases/2.7.1/, "for the current user only". 4) Build and install from the source code setup tools, downloaded from here: https://pypi.python.org/pypi/setuptools#downloads 5) Build and install from the source code virtualenv, downloaded from here: https://pypi.python.org/pypi/virtualenv/1.11.6#downloads 6) Create a virtual python env to hold Trac 0.12.4:
python -m virtualenv trac.0.12.4 trac.0.12.4\Scripts\activate.bat
7) Download Trac 0.12.4 zipped source code from here: http://download.edgewall.org/trac/ 8) Build and install Trac from source:
cd Trac-0.12.4 python setup.py install
9) Created a test project, started with tracd:
trac-admin test initenv trac-admin test permission add anonymous TRAC_ADMIN tracd -r --port 8001 test
10) Install Test Manager 1.5.1, by copying the egg files into the test project plugins directory 11) Stop and start tracd 12) F5 on the browser: upgrade needed hint appears. 13) Stop tracd 14) Run upgrade command:
trac-admin test upgrade
15) Start tracd 16) Create a test catalog, test case, test plan. 17) Stop tracd 18) Install Test Manager 1.8.1, by copying the egg files into the test project plugins directory 19) Start tracd 20) F5 on the browser: upgrade needed hint appears. 21) Stop tracd 22) Run upgrade command:
trac-admin test upgrade
23) Start tracd 24) Everything works fine.
I would like to reproduce your exact environment, and so I'd like understand:
1) How you install Python and is this a fresh installation or an upgrade? I see from your previous comment:
Old Maschine: TestManager-1.5.2-py2.6.egg TracGenericClass-1.1.3-py2.6.egg TracGenericWorkflow-1.0.3-py2.6.egg New Machine: TestManager-1.8.1-py2.7.egg TracGenericClass-1.1.5-py2.7.egg TracGenericWorkflow-1.0.4-py2.7.egg
Does this mean you have upgraded python in the meanwhile and how? Is the new machine a different box? How did you migrate your Trac project?
2) How you install Trac: I see strange paths in your log file:
File "c:\temp\easy_install-hjf2tj\Trac-0.12.4-py2.7-win32.egg.tmp\trac\admin\console.py"
It looks like you have installed Trac using easy_install, but why this strange directory?
3) Is this an upgraded Trac, or a fresh install?
4) How you install Test Manager: do you use the admin panel or do you just copy the egg files? Do you remove the old version files (not sure whether this makes any difference)?
Looking forward for your answers, ciao. Roberto
comment:6 Changed 10 years ago by
I had the same problem when upgrading from TestManager 1.4.9 to 1.8.1 on Trac 0.12.3:
# trac-admin /opt/trac upgrade --no-backup ProgrammingError: relation "testcase" already exists
The postgres log:
ERROR: relation "testcase" already exists STATEMENT: CREATE TABLE "testcase" ( "id" text PRIMARY KEY, "page_name" text, "exec_order" int )
I fixed it by manually adding a testcase_version row:
trac=# INSERT INTO system(name, value) VALUES('testcase_version', '1');
After this the upgrade complained about relation testconfig
, and after fixing that there was more, so in the end I had to add these rows:
trac=# INSERT INTO system(name, value) VALUES('testconfig_version', '1'); trac=# INSERT INTO system(name, value) VALUES('testcasehistory_version', '1'); trac=# INSERT INTO system(name, value) VALUES('testcatalog_version', '1'); trac=# INSERT INTO system(name, value) VALUES('resourceworkflowstate_version', '1');
After these the upgrade went fine.
comment:7 Changed 10 years ago by
Thanks a lot, Tobias, for your help on this.
Still not sure why this happens... it is probably related to how the plugin tries to understand whether the tables are already present or not, which is by checking if a "*_version" table exists (otherwise there is the need to create it) and if so, which version it has in it (in which case there may be the need for a database upgrade).
This is the code to get the current plugin's database version, for a specific "realm" (i.e. "testcase", "testcatalog", ...):
def _get_installed_version(env, realm, db=None): """ :return: -1, if the DB for realm does not exist, a number greater or equals to 1 as the installed DB version for realm. """ version = _get_system_value(env, realm + '_version', None, db) if version is None: # check for old naming schema dburi = env.config.get('trac', 'database') env.log.debug('Database backend is \'%s\'', dburi) tables = list_available_tables(dburi, db.cursor()) if 'tracgenericclassconfig' in tables: version = db_get_config_property(env, 'tracgenericclassconfig', realm + "_dbversion", db) else: if realm in tables: version = 1 if version is None: version = -1 return int(version) def list_available_tables(dburi, cursor): if dburi.startswith('sqlite:'): query = """ SELECT name FROM sqlite_master WHERE type='table' AND NOT name='sqlite_sequence' """ elif dburi.startswith('postgres:'): query = """ SELECT tablename FROM pg_tables WHERE schemaname = ANY (current_schemas(false)) """ elif dburi.startswith('mysql:'): query = "SHOW TABLES" else: raise TracError('Unsupported %s database' % dburi.split(':')[0]) cursor.execute(query) return sorted([row[0] for row in cursor])
What do you think about the postgres section?
Thanks, ciao
Roberto
Hi, same issue here. Old Maschine: TestManager-1.5.2-py2.6.egg TracGenericClass-1.1.3-py2.6.egg TracGenericWorkflow-1.0.3-py2.6.egg
New Machine: TestManager-1.8.1-py2.7.egg TracGenericClass-1.1.5-py2.7.egg TracGenericWorkflow-1.0.4-py2.7.egg
Error: The upgrade failed. Please fix the issue and try again. OperationalError: table testcase already exists
When i disbale the plugin in the trac.ini, upgrade runs fine. If you enable the plugin again it Fails with same error.