Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: don't hardcode client class name. #555

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opensearchpy/_async/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _dynamic_lookup(self, client):
setattr(client, plugin, getattr(self, plugin))
else:
warnings.warn(
f"Cannot load `{plugin}` directly to AsyncOpenSearch. `{plugin}` already exists in AsyncOpenSearch. Please use `AsyncOpenSearch.plugin.{plugin}` instead.",
f"Cannot load `{plugin}` directly to {self.client.__class__.__name__} as it already exists. Use `{self.client.__class__.__name__}.plugin.{plugin}` instead.",
category=RuntimeWarning,
stacklevel=2,
)
5 changes: 1 addition & 4 deletions opensearchpy/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.


import warnings

from ..plugins.alerting import AlertingClient
Expand Down Expand Up @@ -45,9 +44,7 @@ def _dynamic_lookup(self, client):
setattr(client, plugin, getattr(self, plugin))
else:
warnings.warn(
"Cannot load `{plugin}` directly to OpenSearch. `{plugin}` already exists in OpenSearch. Please use `OpenSearch.plugin.{plugin}` instead.".format(
plugin=plugin
),
f"Cannot load `{plugin}` directly to {self.client.__class__.__name__} as it already exists. Use `{self.client.__class__.__name__}.plugin.{plugin}` instead.",
category=RuntimeWarning,
stacklevel=2,
)
24 changes: 24 additions & 0 deletions test_opensearchpy/test_async/test_plugins_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

from unittest import TestCase

from opensearchpy._async.client import AsyncOpenSearch


class TestPluginsClient(TestCase):
async def test_plugins_client(self):
with self.assertWarns(Warning) as w:
client = AsyncOpenSearch()
client.plugins.__init__(client) # double-init
self.assertEqual(
str(w.warnings[0].message),
"Cannot load `alerting` directly to AsyncOpenSearch as it already exists. Use `AsyncOpenSearch.plugin.alerting` instead.",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

from opensearchpy.client import OpenSearch

from ...test_cases import TestCase


class TestPluginsClient(TestCase):
def test_plugins_client(self):
with self.assertWarns(Warning) as w:
client = OpenSearch()
client.plugins.__init__(client) # double-init
self.assertEqual(
str(w.warnings[0].message),
"Cannot load `alerting` directly to OpenSearch as it already exists. Use `OpenSearch.plugin.alerting` instead.",
)
Loading