Modify

Opened 9 years ago

Closed 9 years ago

#12393 closed defect (fixed)

Can't upgrade the database after installing the plugin

Reported by: anonymous Owned by: Cinc-th
Priority: normal Component: SimpleMultiProjectPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

Hello!

My Trac installation is run under uwsgi and uses PostgreSQL 9.4 DB. After I've done svn checkout, built the egg, placed it in the plugins directory, and restarted uwsgi, I run the command: trac-admin /path/to/trac upgrade

It gives me the following error:

ProgrammingError: relation "smp_project" does not exist
LINE 4:                         smp_project
                                ^

Attachments (0)

Change History (15)

comment:1 Changed 9 years ago by falkb

What are your error messages in trac.log? Is there a database table 'smp_project' in your trac.db? Hmm, I thought we already catch the difficulties of PostgreSQL. Look at plugin source file environmentSetup.py. And sorry, I cannot test it because I use SQLite, I just can try blind fixes on suspicion.

comment:2 Changed 9 years ago by anonymous

Hello! Thanks for paying attention to this :)

Here is all concerning this plugin in my trac.log:

2015-06-10 13:50:29,068 Trac[loader] DEBUG: Loading simplemultiproject from /path/to/trac/plugins/SimpleMultiProject-0.0.4dev-py2.7.egg
...
2015-06-10 13:50:29,108 Trac[environmentSetup] DEBUG: SimpleMultiProject database schema version: 0 (should be 6)
2015-06-10 13:50:29,108 Trac[environmentSetup] INFO: SimpleMultiProject database schema version is 0, should be 6
2015-06-10 13:50:29,108 Trac[env] WARNING: Component <simplemultiproject.environmentSetup.smpEnvironmentSetupParticipant object at 0x18a15d0> requires environment upgrade

Table 'smp_project' is not present in the db schema.

I see the file environmentSetup.py in the plugin source directory, but can't figure out what to look for in it on my own. What exactly should or should not be there?

comment:3 Changed 9 years ago by falkb

When you call trac-admin /path/to/trac upgrade you should see those printout() messages you can find in function upgrade_environment of environmentSetup.py. Do they appear on command line? At least "Upgrading SimpleMultiProject database schema" should appear.

comment:4 Changed 9 years ago by anonymous

No, none of the printout() messages appear. It only gives me what I posted:

[root@server trac]# trac-admin /path/to/trac upgrade
ProgrammingError: relation "smp_project" does not exist
LINE 4:                         smp_project
                                ^

comment:5 Changed 9 years ago by falkb

Please, try trac-admin /path/to/trac upgrade again, but before doing that please manually alter trac.db in database table system in a way that the version of SimpleMultiProjectPlugin is 0 again. Then report the console output again. (If you like, you can also insert some more helpful debug printout() messages in the source code of function upgrade_environment() )

comment:6 Changed 9 years ago by anonymous

But the table system only contains these rows:

"database_version";"29" "initial_database_version";"29"

comment:7 in reply to:  6 Changed 9 years ago by falkb

Replying to anonymous:

But the table system only contains these rows:

"database_version";"29" "initial_database_version";"29"

That means this plugin still has version 0, and all if-statements of upgrade_environment() should be executed, and they change the tables. If not, what reasons could be? Maybe permissions for the db file?

comment:8 Changed 9 years ago by falkb

upgrade_environment() succeeded, you should see version 6 as entry for this plugin in the system table.

comment:9 Changed 9 years ago by teabbs

After some explorations I seem to have found the reason.

I understand that I looked at trac.log not after running the upgrade command but just after restarting uwsgi. Actually it contains this:

2015-06-10 19:57:44,282 Trac[environmentSetup] DEBUG: SimpleMultiProject database schema version: 0 (should be 6)
2015-06-10 19:57:44,282 Trac[environmentSetup] INFO: SimpleMultiProject database schema version is 0, should be 6
2015-06-10 19:57:44,282 Trac[env] WARNING: Component <simplemultiproject.environmentSetup.smpEnvironmentSetupParticipant object at 0x2462090> requires environment upgrade
2015-06-10 19:57:44,289 Trac[console] ERROR: Exception in trac-admin command: 
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/trac/admin/console.py", line 109, in onecmd
    rv = cmd.Cmd.onecmd(self, line) or 0
  File "/usr/lib64/python2.7/cmd.py", line 220, in onecmd
    return self.default(line)
  File "/usr/lib/python2.7/site-packages/trac/admin/console.py", line 287, in default
    return self.cmd_mgr.execute_command(*args)
  File "/usr/lib/python2.7/site-packages/trac/admin/api.py", line 120, in execute_command
    for provider in self.providers:
  File "/usr/lib/python2.7/site-packages/trac/core.py", line 78, in extensions
    components = [component.compmgr[cls] for cls in classes]
  File "/usr/lib/python2.7/site-packages/trac/core.py", line 204, in __getitem__
    component = cls(self)
  File "/usr/lib/python2.7/site-packages/trac/core.py", line 140, in __call__
    self.__init__()
  File "build/bdist.linux-x86_64/egg/simplemultiproject/admin_command.py", line 61, in __init__
    self.__SmpModel = SmpModel(self.env)
  File "/usr/lib/python2.7/site-packages/trac/core.py", line 140, in __call__
    self.__init__()
  File "build/bdist.linux-x86_64/egg/simplemultiproject/model.py", line 57, in __init__
    self.get_all_projects()
  File "build/bdist.linux-x86_64/egg/simplemultiproject/model.py", line 102, in get_all_projects
    cursor.execute(query)
  File "/usr/lib/python2.7/site-packages/trac/db/util.py", line 73, in execute
    return self.cursor.execute(sql)
ProgrammingError: relation "smp_project" does not exist
LINE 4:                         smp_project
                                ^
ProgrammingError: relation "smp_project" does not exist
LINE 4:                         smp_project
                                ^

So I went to simplemultiproject/model.py, commented out the query in such a way that the function get_all_projects just returned an empty list. Then I ran the upgrade again, and it finished sucessfully:

Upgrading SimpleMultiProject database schema
SimpleMultiProject database schema version is 0, should be 6
Upgrade done.

You may want to upgrade the Trac documentation now by running:

  trac-admin /var/lib/uwsgi/trac wiki upgrade

Now I have reverted my changes to the model.py, and the plugin seems to work.

Last edited 9 years ago by teabbs (previous) (diff)

comment:10 Changed 9 years ago by falkb

Owner: changed from falkb to Cinc-th
Status: newassigned

Hi Cinc-th, What doesn't work anymore if get_all_projects() is removed from init? Sorry for reassigning but I'm not allowed to set you on CC. :-/

 class SmpModel(Component):
     # needed in self.is_not_in_restricted_users()
     group_providers = ExtensionPoint(IPermissionGroupProvider)
 
     def __init__(self):
         # Make sure we have initial data for the ticket-custom field 'project'.
-        self.get_all_projects()

comment:11 in reply to:  10 Changed 9 years ago by Cinc-th

Replying to falkb:

Hi Cinc-th, What doesn't work anymore if get_all_projects() is removed from init? Sorry for reassigning but I'm not allowed to set you on CC. :-/

 class SmpModel(Component):
     # needed in self.is_not_in_restricted_users()
     group_providers = ExtensionPoint(IPermissionGroupProvider)
 
     def __init__(self):
         # Make sure we have initial data for the ticket-custom field 'project'.
-        self.get_all_projects()

That was part of a patch for #11573. This call is for making sure the drop down list for projects on the ticket query page is properly populated right from the start. Otherwise some info may be missing depending on the usage history of the user.

As a quick workaround removing that line doesn't hurt too much. I've got an idea for a proper fix though.

comment:12 Changed 9 years ago by Cinc-th

Status: assignedaccepted

comment:13 Changed 9 years ago by Cinc-th

In 14662:

Check for upgraded database before calling self.get_all_projects() in init method of SmpModel. This should prevent environment upgrade failure for new installations. Refs #12393.

comment:14 Changed 9 years ago by Cinc-th

Keywords: testing added

comment:15 Changed 9 years ago by Cinc-th

Keywords: testing removed
Resolution: fixed
Status: acceptedclosed

Tested with Trac 0.12.3 and SQLite.

Without the fix SQLite issued an error, with [14662] applied everything is ok.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Cinc-th.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


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

 
Note: See TracTickets for help on using tickets.