Skip to content

Commit

Permalink
Error when multiple configuration plugins are installed (flyteorg#2069)
Browse files Browse the repository at this point in the history
* Error when multiple configuration plugins are installed

Signed-off-by: Thomas J. Fan <[email protected]>

* Adds semi-colon

Signed-off-by: Thomas J. Fan <[email protected]>

---------

Signed-off-by: Thomas J. Fan <[email protected]>
  • Loading branch information
thomasjpfan authored Dec 26, 2023
1 parent 0e8abd9 commit e107994
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion flytekit/configuration/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def _get_plugin_from_entrypoint():

if len(plugins) >= 2:
plugin_names = [p.name for p in plugins]
logger.info(f"Multiple plugins seen for {group}: {plugin_names}")
raise ValueError(
f"Multiple plugins installed: {plugin_names}. flytekit only supports one installed plugin at a time."
)

plugin_to_load = plugins[0]
logger.info(f"Loading plugin: {plugin_to_load.name}")
Expand Down
17 changes: 9 additions & 8 deletions tests/flytekit/unit/cli/pyflyte/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
from unittest.mock import Mock, patch

import click
import pytest

from flytekit.configuration.plugin import FlytekitPlugin, FlytekitPluginProtocol, _get_plugin_from_entrypoint

Expand All @@ -14,20 +16,19 @@ def test_get_plugin_default(entry_points):


@patch("flytekit.configuration.plugin.entry_points")
def test_get_plugin_load_other_plugin(entry_points, caplog):
loaded_plugin_1 = Mock()
def test_get_plugin_errors_with_multiple_plugins(entry_points, caplog):
entry_1 = Mock()
entry_1.name = "entry_1"
entry_1.load.side_effect = lambda: loaded_plugin_1

entry_2 = Mock()
entry_2.name = "entry_2"
entry_points.side_effect = lambda *args, **kwargs: [entry_1, entry_2]

plugin = _get_plugin_from_entrypoint()
assert plugin is loaded_plugin_1

assert entry_1.load.call_count == 1
assert entry_2.load.call_count == 0
msg = re.escape(
"Multiple plugins installed: ['entry_1', 'entry_2']. flytekit only supports one installed plugin at a time."
)
with pytest.raises(ValueError, match=msg):
_get_plugin_from_entrypoint()


class CustomPlugin(FlytekitPlugin):
Expand Down

0 comments on commit e107994

Please sign in to comment.