ModuleAvailableFeature broken for modules with side-effects

Bug #712474 reported by Vincent Ladeuil
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Medium
Vincent Ladeuil
BzrTools
Invalid
Undecided
Unassigned

Bug Description

ModuleAvailableFeature uses the following code to check for the presence of a module:

    def _probe(self):
        try:
            self._module = __import__(self.module_name, {}, {}, [''])
            return True
        except ImportError:
            return False

This fails for 'bzrlib.plugins.svn' with:

    self._module = __import__(self.module_name, {}, {}, [''])
  File "/home/vila/.bazaar/plugins/svn/__init__.py", line 140, in <module>
    help="Access using the Subversion smart server tunneled over SSH.")
  File "/home/vila/src/bzr/trunk/bzrlib/transport/__init__.py", line 135, in register_transport_proto
    transport_list_registry.register_transport(prefix, help)
  File "/home/vila/src/bzr/trunk/bzrlib/transport/__init__.py", line 123, in register_transport
    self.register(key, [], help)
  File "/home/vila/src/bzr/trunk/bzrlib/registry.py", line 117, in register
    raise KeyError('Key %r already registered' % key)
KeyError: "Key 'svn+ssh://' already registered"

Because the plugin has already been imported and its init code has already run.

- self._module = __import__(self.module_name, {}, {}, [''])
+ exec 'import %s' % (self.module_name)
+ self._module = sys.modules[self.module_name]

fixes the problem.

I'll submit patch.

Related branches

Vincent Ladeuil (vila)
Changed in bzr:
status: New → Confirmed
assignee: nobody → Vincent Ladeuil (vila)
Vincent Ladeuil (vila)
Changed in bzr:
status: Confirmed → In Progress
importance: Undecided → Medium
Vincent Ladeuil (vila)
Changed in bzr:
status: In Progress → Fix Released
milestone: none → 2.5b1
Aaron Bentley (abentley)
Changed in bzrtools:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.