From 15192c6b1e6c9e1071e8d9334b75fcbed45740fd Mon Sep 17 00:00:00 2001
From: "Thomas J. Fan" <thomasjpfan@gmail.com>
Date: Fri, 22 Dec 2023 15:39:58 -0500
Subject: [PATCH 1/2] Error when multiple configuration plugins are installed

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
---
 flytekit/configuration/plugin.py               |  4 +++-
 tests/flytekit/unit/cli/pyflyte/test_plugin.py | 17 +++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/flytekit/configuration/plugin.py b/flytekit/configuration/plugin.py
index 85bc811c44..f5397d171d 100644
--- a/flytekit/configuration/plugin.py
+++ b/flytekit/configuration/plugin.py
@@ -73,7 +73,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}")
diff --git a/tests/flytekit/unit/cli/pyflyte/test_plugin.py b/tests/flytekit/unit/cli/pyflyte/test_plugin.py
index 6e3423a1ca..0391a291aa 100644
--- a/tests/flytekit/unit/cli/pyflyte/test_plugin.py
+++ b/tests/flytekit/unit/cli/pyflyte/test_plugin.py
@@ -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
 
@@ -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):

From dc063a308513b15a04e22ad567d58ba4a0ef0f49 Mon Sep 17 00:00:00 2001
From: "Thomas J. Fan" <thomasjpfan@gmail.com>
Date: Fri, 22 Dec 2023 20:48:07 -0500
Subject: [PATCH 2/2] Adds semi-colon

Signed-off-by: Thomas J. Fan <thomasjpfan@gmail.com>
---
 flytekit/configuration/plugin.py               | 2 +-
 tests/flytekit/unit/cli/pyflyte/test_plugin.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/flytekit/configuration/plugin.py b/flytekit/configuration/plugin.py
index f5397d171d..2db4964419 100644
--- a/flytekit/configuration/plugin.py
+++ b/flytekit/configuration/plugin.py
@@ -74,7 +74,7 @@ def _get_plugin_from_entrypoint():
     if len(plugins) >= 2:
         plugin_names = [p.name for p in plugins]
         raise ValueError(
-            f"Multiple plugins installed {plugin_names}. flytekit only supports one installed plugin at a time."
+            f"Multiple plugins installed: {plugin_names}. flytekit only supports one installed plugin at a time."
         )
 
     plugin_to_load = plugins[0]
diff --git a/tests/flytekit/unit/cli/pyflyte/test_plugin.py b/tests/flytekit/unit/cli/pyflyte/test_plugin.py
index 0391a291aa..5d7b8d8bf6 100644
--- a/tests/flytekit/unit/cli/pyflyte/test_plugin.py
+++ b/tests/flytekit/unit/cli/pyflyte/test_plugin.py
@@ -25,7 +25,7 @@ def test_get_plugin_errors_with_multiple_plugins(entry_points, caplog):
     entry_points.side_effect = lambda *args, **kwargs: [entry_1, entry_2]
 
     msg = re.escape(
-        "Multiple plugins installed ['entry_1', 'entry_2']. flytekit only supports one installed plugin at a time."
+        "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()
