#7656 closed defect (worksforme)
IEnvironmentSetupParticipant doesn't have default Component attributes
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | general | Version: | 0.11.1 |
| Severity: | major | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
As stated here every Component automatically gets the three extra member variables env, config and log. However this seems not to be true for components implementing (only?) IEnvironmentSetupParticipant.
The three member variables are available in the methods environment_needs_upgrade (could not check environment_created or upgrade_environment) but they are defenitely not available in __init__ nor in any other method.
Here's an example code:
from trac.core import * from trac.env import IEnvironmentSetupParticipant class ThemeAdminPanelDB(Component): """Class that deals with database access, setup and upgrades.""" implements(IEnvironmentSetupParticipant) def __init__(self): # NOT available here test = self.env pass # IEnvironmentSetupParticipant methods def environment_created(self): """Called when a new Trac environment is created.""" pass def environment_needs_upgrade(self, db): """Called when Trac checks whether the environment needs to be upgraded. Returns `True` if upgrade is needed, `False` otherwise.""" # available here test = self.env return False def upgrade_environment(self, db): """Actually perform an environment upgrade, but don't commit as that is done by the common upgrade procedure when all plugins are done.""" pass # Own methods def get_db_version(self, db = None): # NOT available here test = self.env return 0
To call get_db_version I used the following code (as stated here):
comp_mgr = ComponentManager() db_mgr = ThemeAdminPanelDB(comp_mgr) version = db_mgr.get_db_version()
So either it's a bug or the documentation isn't correct and should state this exception.
Third possibility: I've just recently learned Python so my Python abilities are very limited. For example: Shouldn't self be the same "instance" in every method of this class? According to this they should be:
comp_mgr = ComponentManager() my_comp1 = MyComponent(comp_mgr) my_comp2 = MyComponent(comp_mgr) assert id(my_comp1) == id(my_comp2)
Attachments (0)
Change History (2)
comment:1 by , 17 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 17 years ago
You were right. I didn't passed an Environment to the constructor because I didn't know I had to. Now it works.
Is this the way it works for all Components or only for IEnvironmentSetupParticipant? In any way: Should the documentation here not be corrected so that your way is documented?



Tried your plugin, and it loads fine at my end meaning your test statements evaluates correctly.
I think this is just a problem stemming from reading the original proposal for the feature that may not quite be in line with how it works in actual implemented code. Instantiating components takes an
envas first argument, and theenvhas a component manager attached. Your test code does not as far as I can see instantiate anenv?This works:
Use the trac-dev MailingList or get onto the #trac IrcChannel if you have further development-related questions.