Trac AttributeError: 'str' object has no attribute 'db_query' error when trying to get Components available in the system

StackOverflow https://stackoverflow.com/questions/21435114

  •  04-10-2022
  •  | 
  •  

Question

I'm trying get all components in the current environment, but a reason I can't understand I get the following error:

AttributeError: 'str' object has no attribute 'db_query'

Here is the code (some parts are skipped):

  from trac.core import *
  from trac.ticket import model

  class TracIteraDirectory(Component):

  implements(INavigationContributor, ITemplateProvider, IRequestHandler)

  def process_request(self, req):
       myenv = '/home/konart/backup/Trac/TracDB/Planing'
       self.db = self.env.get_db_cnx()

       components = []
       test = model.Component(myenv)
       test1 = test.select(myenv)

       for each in test1:
           components.append((each.name, each.owner))

       #for component in model.Component(myenv).select(myenv):
           #components.append((component.name, component.owner))

I've checked out some plugin exanples on trac-hacks.org and core files, but just can't understand what I'm doing wrong here (or not doing at all)

Was it helpful?

Solution

I guess I overworked a bit. The answer was really simple - I was passing a simple string with a path to my env, instead of passing an actual Environment object:

def process_request(self, req):

    if req.path_info.startswith('/traciteradirectory'):

        components = []
        test = model.Component(self.env)
        test1 = test.select(self.env)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top