Opened 6 years ago

Closed 6 years ago

AttributeError: 'Environment' object has no attribute 'get_read_db'

Reported by: Owned by: Gustavo Rubio Christopher Paredes normal SimpleMultiProjectPlugin blocker 0.11

Description

Hi, I compiled and installed the plugin and then did the trac instance upgrade as pointed by the installation. The "Projects" link appears in the admin panel but as soon as I click on it a message appears:

Trac detected an internal error:
AttributeError: 'Environment' object has no attribute 'get_read_db'


First let me say that I actually don't know if this plugin is intended to be only used in trac 0.12.x instances. I have 0.11.7 installed running on FastCGI with SQLite. The reason I'm reporting this issue is because I did not find any information regarding the versio needed on the hacks page. That being said, I googled a little bit about the error, which is shown as a general Trac, error and found something similar for another hack in #8854, I followed the instructions on one of the comments to do this:

import trac
trac.__version__   # verify that this returns a trac 12 version
>> '0.12.3dev-r10639'

# verify you can connect to the database from python
import trac.env
e = trac.env.Environment('/var/trac/test') # enter your trac instance directory
cur = db.cursor()
cur.execute("SELECT 1")
data = cur.fetchone()


Then, as soon as I get to the db = e.get_read_db() line I get this exception:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Environment' object has no attribute 'get_read_db'


Which is of course the same as the exception shown on the Trac page itself when clicking the Projects link. I just want to clear this since the guy on the #8854 ticket got something different after trying the same.

My thoughts are that this is actually a 0.12 > plugin and it won't work on my trac. If this is the case please disregard my ticket but it would be good if the required version was mentioned on the hack page. I've seen some other tickets reported for this plugin with the 0.11 version selected so I still have hopes :)

If you need anything else please let me know.

comment:1 Changed 6 years ago by Gustavo Rubio

Just as a side note, I ran the trac-admin upgrade just in case and I got this:

SimpleMultiProject database schema version: 1 initialized.
SimpleMultiProject database schema is out of date: False
Database is up to date, no upgrade necessary.


comment:2 Changed 6 years ago by Christopher Paredes

hello,

Thanks for reporting the problem

The ticket # 8854, you said your problem solved by doing the following:

Problem Was That the trac.ini file readable by not was the user the server is running as. Somewhere along the way I must-have changed the perms.

Hopefully I can work on your trac :)

comment:3 Changed 6 years ago by anonymous

Status: new → assigned

Reviewing documentation of the api

Environment.get_db_cnx is deprecated

Due to the new support for automated transaction management, Connection instances should no longer be acquired using the familiar get_db_cnx method, as it doesn't tell whether the connection will be used as part of a write transaction or purely for queries. Instead, one should use:

env.get_read_db for obtaining a Connection suitable for read queries (i.e. SELECT) the env.with_transaction decorator, for using a db parameter in a transaction function which should be committed when the last such automatic transaction in the control flow completes successfully (see details further down)

Using env.get_db_cnx still works, but any explicit transaction management will risk to prematurely end a higher level transaction set up via with_transaction at a previous level in the control flow.

reviewing documentation of the api

function 'get_read_db' was introduced with version 0.12 of trac.

Would have to find a way to make it work with any such condition.

comment:4 Changed 6 years ago by falkb

grubio, is this still a problem? Meanwhile the plugin has been changed, heavily. Probably, your problem has been fixed during those sessions. Waiting for your reply...

comment:5 Changed 6 years ago by falkb

(In [11787]) Refs #10068: get_read_db is not available in older Trac version, use get_db_cnx() instead

comment:6 Changed 6 years ago by anonymous

Does [11787] fix this error? Could anybody with older than 0.12 test, please?

comment:7 Changed 6 years ago by falkb

Resolution: → fixed assigned → closed

Timeout. The special reported error should have been fixed.

P.S.: further handling of a 0.11 backport is in #10078

Modify Ticket

Change Properties