movePluginsUp when called on the top plugin moves it down

Bug #164717 reported by Maurits van Rees
2
Affects Status Importance Assigned to Milestone
Zope PAS
Fix Released
Low
Wichert Akkerman

Bug Description

This is for the PluginRegistry product.

When you call movePluginsUp on the plugin that is already the top one, it is actually moved to the bottom. And the bottom plugin is moved to the top instead.

Most interesting is the simple case where you have two plugins registered for an interface.

- All four combinations of calling movePluginsUp or Down on the top or the bottom one have the same result: the positions are switched.

- Calling two of those random actions after one another has zero end effect.

This can be fixed with the below patch, with tests.

Index: tests/test_PluginRegistry.py
===================================================================
--- tests/test_PluginRegistry.py (revision 81966)
+++ tests/test_PluginRegistry.py (working copy)
@@ -208,6 +208,19 @@
         self.assertEqual( idlist[1], 'baz_plugin' )
         self.assertEqual( idlist[2], 'foo_plugin' )

+ # Moving the top plugin up should not change anything.
+ preg.movePluginsUp( IFoo, ( 'bar_plugin', ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqual(idlist,
+ ('bar_plugin', 'baz_plugin', 'foo_plugin'))
+
+ # Moving the top plugin and another one could change something.
+ preg.movePluginsUp( IFoo, ( 'bar_plugin', 'foo_plugin' ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqual(idlist,
+ ('bar_plugin', 'foo_plugin', 'baz_plugin'))
+
+
     def test_movePluginsDown( self ):

         parent = DummyFolder()
@@ -241,6 +254,18 @@
         self.assertEqual( idlist[1], 'foo_plugin' )
         self.assertEqual( idlist[2], 'bar_plugin' )

+ # Moving the lowest plugin down should not change anything.
+ preg.movePluginsDown( IFoo, ( 'bar_plugin', ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqual(idlist,
+ ('baz_plugin', 'foo_plugin', 'bar_plugin'))
+
+ # Moving the lowest plugin and another one could change something.
+ preg.movePluginsDown( IFoo, ( 'bar_plugin', 'baz_plugin' ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqual(idlist,
+ ('foo_plugin', 'baz_plugin', 'bar_plugin'))
+
     def test_getAllPlugins( self ):

         parent = DummyFolder()
Index: PluginRegistry.py
===================================================================
--- PluginRegistry.py (revision 81966)
+++ PluginRegistry.py (working copy)
@@ -202,8 +202,9 @@
                 raise IndexError, i1

             i2 = i1 - 1
- if i2 < 0: # wrap to bottom
- i2 = len( ids ) - 1
+ if i2 < 0:
+ # i1 is already on top
+ continue

             ids[ i2 ], ids[ i1 ] = ids[ i1 ], ids[ i2 ]

@@ -227,8 +228,9 @@
                 raise IndexError, i1

             i2 = i1 + 1
- if i2 == len( ids ): # wrap to top
- i2 = 0
+ if i2 == len( ids ):
+ # i1 is already on the bottom
+ continue

             ids[ i2 ], ids[ i1 ] = ids[ i1 ], ids[ i2 ]

Revision history for this message
Maurits van Rees (maurits-vanrees) wrote :

I will add the patch as an attachment, which can be applied like this:
patch -p0 < patch-moveplugins.txt

Changed in zope-pas:
assignee: nobody → wichert
importance: Undecided → Low
status: New → In Progress
Changed in zope-pas:
status: In Progress → Fix Committed
Revision history for this message
Tres Seaver (tseaver) wrote :

Fix released with Products.PluginRegistry 1.1.3:

 http://pypi.python.org/pypi/Products.PluginRegistry/1.1.3

Changed in zope-pas:
status: Fix Committed → Fix Released
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.