Modify

Opened 3 years ago

Closed 2 years ago

#12663 closed defect (fixed)

[PATCH]: Exception during database upgrade

Reported by: Cinc-th Owned by: Roberto Longobardi
Priority: normal Component: TestManagerForTracPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

This is a problem with the TracGenericClass plugin.

There is no upgrade script available and the exception happens while creating the message string for the raise TracError() call.

14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2
14:47:39 Trac[model] DEBUG: No need to create database for class 'peerreview'.
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2. Desired version is 3
14:47:39 Trac[model] INFO: Need to update db tables for class 'peerreview'.
14:47:39 Trac[env] WARNING: Component <codereview.model.GenericWorkflowModelProvider object at 0x10d2e6810> requires environment upgrade
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2
14:47:39 Trac[model] DEBUG: No need to create database for class 'peerreview'.
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2. Desired version is 3
14:47:39 Trac[model] INFO: Need to update db tables for class 'peerreview'.
14:47:39 Trac[env] WARNING: Component <codereview.model.GenericWorkflowModelProvider object at 0x10d2e6810> requires environment upgrade
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2
14:47:39 Trac[model] DEBUG: No need to create database for class 'peerreview'.
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2. Desired version is 3
14:47:39 Trac[model] INFO: Need to update db tables for class 'peerreview'.
14:47:39 Trac[env] INFO: codereview.model.GenericWorkflowModelProvider upgrading...
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2
14:47:39 Trac[model] DEBUG: No need to create database for class 'peerreview'.
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Current database version for class 'peerreview' is 2. Desired version is 3
14:47:39 Trac[model] INFO: Need to update db tables for class 'peerreview'.
14:47:39 Trac[model] INFO: Upgrading DB for class 'peerreview'.
14:47:39 Trac[model] DEBUG: Found system key 'peerreview_version' with value 2
14:47:39 Trac[model] DEBUG: Returning system key 'peerreview_version' with value 2
14:47:39 Trac[model] INFO: Upgrading database version for class 'peerreview' from 2 to 3
The upgrade failed. Please fix the issue and try again.

TypeError: 'dict' object is not callable
14:47:39 Trac[console] ERROR: Exception in trac-admin command: 
Traceback (most recent call last):
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/admin/console.py", line 109, in onecmd
    rv = cmd.Cmd.onecmd(self, line) or 0
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cmd.py", line 220, in onecmd
    return self.default(line)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/admin/console.py", line 287, in default
    return self.cmd_mgr.execute_command(*args)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/admin/api.py", line 127, in execute_command
    return f(*fargs)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/env.py", line 1025, in _do_upgrade
    self.env.upgrade(backup=no_backup is None)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/env.py", line 761, in upgrade
    participant.upgrade_environment(db)
  File "build/bdist.macosx-10.8-x86_64/egg/codereview/model.py", line 152, in upgrade_environment
    @self.env.with_transaction(db)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/db/api.py", line 93, in transaction_wrapper
    fn(db)
  File "build/bdist.macosx-10.8-x86_64/egg/codereview/model.py", line 161, in do_upgrade_environment
    upgrade_db_for_realm(self.env, 'codereview.upgrades', realm, realm_metadata, db)
  File "build/bdist.macosx-10.8-x86_64/egg/codereview/tracgenericclass/model.py", line 1392, in upgrade_db_for_realm
    @env.with_transaction(db)
  File "/Users/cinc/projects/Trac-1.0.x-Python2.7.11/lib/python2.7/site-packages/trac/db/api.py", line 93, in transaction_wrapper
    fn(db)
  File "build/bdist.macosx-10.8-x86_64/egg/codereview/tracgenericclass/model.py", line 1417, in do_upgrade_db_for_realm
    '(%(version)s.py)', num=i, version=name))
TypeError: 'dict' object is not callable

The following function is executed:

def upgrade_db_for_realm(env, package_name, realm, realm_schema, db=None):
    """
    Each db version should have its own upgrade module, named
    upgrades/db_<schema>_<N>.py, where 'N' is the version number (int).
    """
    @env.with_transaction(db)
    def do_upgrade_db_for_realm(db):
        cursor = db.cursor()

        db_backend, _ = DatabaseManager(env).get_connector()

        env.log.info("Upgrading DB for class '%s'.", realm)

        # Create the required tables
        table_metadata = realm_schema['table']
        version = realm_schema['version']
        tablename = table_metadata.name

        cursor = db.cursor()
        current_version = _get_installed_version(env, realm, db)

        for i in range(current_version + 1, version + 1):
            env.log.info('Upgrading database version for class \'%s\' from %d to %d', realm, i - 1, i)

            name  = 'db_%s_%i' % (realm, i)
            try:
                upgrades = __import__(package_name, globals(), locals(), [name])
                script = getattr(upgrades, name)
            except AttributeError:
                raise TracError(_('No upgrade module for version %(num)i '
                                  '(%(version)s.py)', num=i, version=name))
            script.do_upgrade(env, i, db_backend, db)

            _set_installed_version(env, realm, i, db)

            env.log.info('Upgrade step successful.')

The line

    db_backend, _ = DatabaseManager(env).get_connector()

overwrites the translation function

    _()

Changing it to

    db_backend = DatabaseManager(env).get_connector()[0]

fixes the problem.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by Cinc-th

In 15231:

Fix possible exception durin environment upgrade if upgrade script isn't available.

See #12663 for an explanation

comment:2 Changed 2 years ago by Roberto Longobardi

Thanks a lot for the patch.

Included in release 1.9.1 now available from SourceForge.

https://sourceforge.net/projects/testman4trac/files

comment:3 Changed 2 years ago by Roberto Longobardi

Resolution: fixed
Status: newclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Roberto Longobardi.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.