trac-hacks / trac-subtickets-plugin

A sub-ticket support plugin for trac
4 stars 4 forks source link

AttributeError: 'Environment' object has no attribute 'get_db_cnx' #4

Closed emecas closed 7 years ago

emecas commented 7 years ago

Getting the error message after installing trac-subtickets-plugin when click to open a ticket

Python Traceback
Most recent call last:

    File "/usr/lib64/python2.7/site-packages/trac/web/main.py", line 613, in _dispatch_request
    File "/usr/lib64/python2.7/site-packages/trac/web/main.py", line 263, in dispatch
    File "/usr/lib64/python2.7/site-packages/trac/web/main.py", line 444, in _post_process_request
    File "build/bdist.linux-x86_64/egg/tracsubtickets/web_ui.py", line 73, in post_process_request
    File "build/bdist.linux-x86_64/egg/tracsubtickets/web_ui.py", line 104, in get_children 

Issue stops once the plugin is disable


System Information

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
Package Version
Trac    1.2
Genshi  0.7 (without speedups)
psycopg2    2.5.1
Python  2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
setuptools  28.8.0
jQuery  1.11.3
jQuery UI   1.11.4
jQuery Timepicker   1.5.5
Installed Plugins
Name    Version Location
ComponentDependencyPlugin   0.1     /usr/lib/python2.7/site-packages/ComponentDependencyPlugin-0.1-py2.7.egg
TicketSidebarProvider   0.0.post0   /usr/lib/python2.7/site-packages/TicketSidebarProvider-0.0.post0-py2.7.egg
TracHoursPlugin     0.6.0.dev0  /usr/lib/python2.7/site-packages/TracHoursPlugin-0.6.0.dev0-py2.7.egg
TracSubTicketsPlugin    0.3.0.dev0  /usr/lib/python2.7/site-packages/TracSubTicketsPlugin-0.3.0.dev0-py2.7.egg
thenor57 commented 7 years ago

I suspect that the reason is that you use Trac 1.2 where the database API is changed. I have not yet tested that. Can you please give me the exception message given with the stack trace?

emecas commented 7 years ago

Yes, you are right, that is the cause.

This is the exception message:

Oops…
Trac detected an internal error:

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

This is similar to: https://trac-hacks.org/ticket/12934 , it has a patch already, replacing the old env.get_db_cnx API with the new env.db_transaction API.

thenor57 commented 7 years ago

Good. I'm aware of the patch and it is on my to-do list to integrate it now 1.2 is released. With a little luck next week...

emecas commented 7 years ago

Thanks.

This one looks a little more complicate than the one I just patched, what I'm no sure yet it's about backward compatibility.

There are 6 calls to the self.env.get_db_cnx() statement in 2 the modules:

api.py (4 hits)
    Line 72:         self.upgrade_environment(self.env.get_db_cnx())
    Line 147:         db = self.env.get_db_cnx()
    Line 174:         db = self.env.get_db_cnx()
    Line 185:         db = self.env.get_db_cnx()

web_ui.py (2 hits)
    Line 104:             db = self.env.get_db_cnx()
    Line 120:             db = self.env.get_db_cnx()

Now my question is: would it be enough just by replacing the call logic for a with self.env.db_transaction as db: block and in addition will it keep compatibility to previous versions?

If this is all we need to consider then I can help if you want it.

lxbzmy commented 7 years ago

+1.

thenor57 commented 7 years ago

Good. I'm aware of the patch and it is on my to-do list to integrate it now 1.2 is released. With a little luck next week...

thenor57 commented 7 years ago

I've a patch working on Trac 1.0; hope to test it on 1.2 tomorrow or Wednesday and then commit to a new branch. Will appreciate if you'll try it out too, before I merge into master.

Re your question: That is exactly what I've done so far.

emecas commented 7 years ago

Sure, I can try it in ahead.

Can you please provide a link to the changeset/commit you want me to test.

Thanks!!

rjollos commented 7 years ago

I'd be happy to help with review if you'd like to put it in a pull request.

thenor57 commented 7 years ago

Thanks both. Pull request created.