Modify

Opened 8 years ago

Closed 8 years ago

#13119 closed defect (fixed)

Exception caught while checking for upgrade

Reported by: Andrew Schulman Owned by: Ryan J Ollos
Priority: normal Component: DefaultCcPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.2

Description

I see the following in the Trac log on every request:

2017-03-20 11:28:35,490 Trac[env] ERROR: Exception caught while checking for upgrade:
Traceback (most recent call last):
  File "/srv/usr/lib/python2.6/site-packages/Trac-1.2-py2.6.egg/trac/env.py", line 934, in open_environment
    needs_upgrade = env.needs_upgrade()
  File "/srv/usr/lib/python2.6/site-packages/Trac-1.2-py2.6.egg/trac/env.py", line 793, in needs_upgrade
    if participant.environment_needs_upgrade(*args):
  File "build/bdist.linux-x86_64/egg/defaultcc/admin.py", line 50, in environment_needs_upgrade
    return 'component_default_cc' not in self._get_tables()
  File "build/bdist.linux-x86_64/egg/defaultcc/admin.py", line 75, in _get_tables
    return sorted(row[0] for row in self.env.db_transaction(query))
TypeError: 'NoneType' object is not iterable

Fortunately the user doesn't see any errors because of this.

I get the same thing when I try to run trac-admin upgrade:

$ trac-admin /srv/var/lib/trac upgrade
Error: TypeError: 'NoneType' object is not iterable

This is with version 0.4dev, r16356.

Attachments (1)

t13119.diff (689 bytes) - added by Ryan J Ollos 8 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by Andrew Schulman

Looking at _get_tables() in admin.py, it seems that in the final line, self.env.db_transaction(query)) is returning None, and I'm not sure why. By logging I determined that:

dburi = 'database = mysql://trac:PMwbTmF7QaYaKfHm@localhost:3306/trac'
query = 'SHOW TABLES'
self.env.db_transaction(query)) = None

comment:2 Changed 8 years ago by Ryan J Ollos

The query doesn't seem to work for me either. Could you please try the following?:

  • defaultcc/admin.py

     
    6969            query = "SELECT tablename FROM pg_tables" \
    7070                    " WHERE schemaname = ANY (current_schemas(false))"
    7171        elif dburi.startswith('mysql:'):
    72             query = "SHOW TABLES"
     72            query = "SELECT table_name FROM information_schema.tables "
     73                    " WHERE table_type='BASE TABLE'"
    7374        else:
    7475            raise TracError('Unsupported %s database' % dburi.split(':')[0])
    7576        return sorted(row[0] for row in self.env.db_transaction(query))

Taken from SO:42441139/121694.

Changed 8 years ago by Ryan J Ollos

Attachment: t13119.diff added

comment:3 Changed 8 years ago by anonymous

Yes, that fixes the problem for me. And it also allows you to call qb_query instead of db_transaction, for a read-only connection.

I don't know why SHOW TABLES doesn't work in MySQL, or if it worked before, why it doesn't now. I can log into mysql as user trac and run SHOW TABLES, and it works fine. Strange.

comment:4 Changed 8 years ago by Jun Omae

That can be reproduced but weird.

Python 2.6.9 (default, Oct 22 2014, 19:56:52)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.test import EnvironmentStub
>>> env = EnvironmentStub()
>>> from trac.db.api import DatabaseManager
>>> dbmgr = DatabaseManager(env)
>>> dbmgr.connection_uri
u'mysql://tracuser:password@127.0.0.1/trac_utf8mb4'
>>> env.db_transaction('SHOW TABLES')
>>> env.db_transaction('SHOW TABLES') is None
True
>>> env.db_query('SHOW TABLES')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/trac/1.2/lib/python2.6/site-packages/trac/db/api.py", line 122, in execute
    return db.execute(query, params)
  File "/venv/trac/1.2/lib/python2.6/site-packages/trac/db/util.py", line 126, in execute
    dql = self.check_select(query)
  File "/venv/trac/1.2/lib/python2.6/site-packages/trac/db/util.py", line 161, in check_select
    raise ValueError("a 'readonly' connection can only do a SELECT")
ValueError: a 'readonly' connection can only do a SELECT
>>> env.db_transaction('SELECT 1')
[(1L,)]
>>> with env.db_transaction as db:
...   cursor = db.cursor()
...   cursor.execute('SHOW TABLES')
...   list(cursor)
...
21L
[(u'attachment',), (u'auth_cookie',), (u'cache',), (u'component',), (u'enum',), (u'milestone',), (u'node_change',), (u'notify_subscription',), (u'notify_watch',), (u'permission',), (u'report',), (u'repository',), (u'revision',), (u'session',), (u'session_attribute',), (u'system',), (u'ticket',), (u'ticket_change',), (u'ticket_custom',), (u'version',), (u'wiki',)]
>>> with env.db_query as db:
...   cursor = db.cursor()
...   cursor.execute('SHOW TABLES')
...   list(cursor)
...
21L
[(u'attachment',), (u'auth_cookie',), (u'cache',), (u'component',), (u'enum',), (u'milestone',), (u'node_change',), (u'notify_subscription',), (u'notify_watch',), (u'permission',), (u'report',), (u'repository',), (u'revision',), (u'session',), (u'session_attribute',), (u'system',), (u'ticket',), (u'ticket_change',), (u'ticket_custom',), (u'version',), (u'wiki',)]

comment:5 in reply to:  4 Changed 8 years ago by Jun Omae

That can be reproduced but weird.

>>> env.db_transaction('SHOW TABLES') is None
True

I found ConnectionWrapper.execute returns None for non-query statements at source:/tags/trac-1.2/trac/db/util.py@:126,129#L117. We could change like t13119.diff or execute SHOW TABLES via db.cursor().

comment:6 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: newclosed

In 16359:

0.4dev: Fix query for tables on MySQL returning None

Patch by Jun Omae. Thanks to Andrew Schulman for reporting and testing.

Fixes #13119.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
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.