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

Add deprecation warnings #13927

Merged
merged 2 commits into from
Nov 10, 2023
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
23 changes: 23 additions & 0 deletions ingestion/src/metadata/ingestion/ometa/mixins/glossary_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PatchValue,
)
from metadata.ingestion.ometa.utils import model_str
from metadata.utils.deprecation import deprecated
from metadata.utils.logger import ometa_logger

logger = ometa_logger()
Expand All @@ -44,6 +45,7 @@ class GlossaryMixin(OMetaPatchMixinBase):
To be inherited by OpenMetadata
"""

@deprecated(message="Use metadata.create_or_update instead", release="1.3")
def create_glossary(self, glossaries_body):
"""Method to create new Glossary
Args:
Expand All @@ -54,6 +56,7 @@ def create_glossary(self, glossaries_body):
)
logger.info(f"Created a Glossary: {resp}")

@deprecated(message="Use metadata.create_or_update instead", release="1.3")
def create_glossary_term(self, glossary_term_body):
"""Method to create new Glossary Term
Args:
Expand All @@ -64,6 +67,10 @@ def create_glossary_term(self, glossary_term_body):
)
logger.info(f"Created a Glossary Term: {resp}")

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_glossary_term_parent(
self,
entity_id: Union[str, basic.Uuid],
Expand Down Expand Up @@ -133,6 +140,10 @@ def patch_glossary_term_parent(

return None

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_glossary_term_related_terms(
self,
entity_id: Union[str, basic.Uuid],
Expand Down Expand Up @@ -221,6 +232,10 @@ def patch_glossary_term_related_terms(

return None

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_reviewers(
self,
entity: Union[Type[Glossary], Type[GlossaryTerm]],
Expand Down Expand Up @@ -307,6 +322,10 @@ def patch_reviewers(

return None

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_glossary_term_synonyms(
self,
entity_id: Union[str, basic.Uuid],
Expand Down Expand Up @@ -385,6 +404,10 @@ def patch_glossary_term_synonyms(

return None

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_glossary_term_references(
self,
entity_id: Union[str, basic.Uuid],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
PatchValue,
)
from metadata.ingestion.ometa.utils import model_str
from metadata.utils.deprecation import deprecated
from metadata.utils.logger import ometa_logger

logger = ometa_logger()
Expand Down Expand Up @@ -129,6 +130,10 @@ def _get_optional_rule_patch(
]
return data

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_role_policy(
self,
entity_id: Union[str, basic.Uuid],
Expand Down Expand Up @@ -261,6 +266,10 @@ def patch_role_policy(

return None

@deprecated(
message="Use metadata.patch instead as the new standard method that will create the jsonpatch dynamically",
release="1.3",
)
def patch_policy_rule(
self,
entity_id: Union[str, basic.Uuid],
Expand Down
35 changes: 35 additions & 0 deletions ingestion/src/metadata/utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Announce method deprecation
"""
import warnings
from functools import wraps


def deprecated(message: str, release: str):
"""Decorator factory to accept specific messages for each function"""

def _deprecated(fn):
@wraps(fn)
def inner(*args, **kwargs):
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
f"[{fn.__name__}] will be deprecated in the release [{release}]: {message}",
category=DeprecationWarning,
)
warnings.simplefilter("default", DeprecationWarning)

return fn(*args, **kwargs)

return inner

return _deprecated
39 changes: 39 additions & 0 deletions ingestion/tests/unit/utils/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Test deprecation warnings
"""

import warnings
from unittest import TestCase

from metadata.utils.deprecation import deprecated


class TestDeprecationWarning(TestCase):
"""Test deprecation warnings are properly displayed"""

@deprecated(message="This is a deprecation", release="x.y.z")
def deprecated_call(self) -> None:
"""Sample method"""

def test_deprecation_warning(self) -> None:
"""Validate warning"""

with warnings.catch_warnings(record=True) as warn:
# Trigger the warning
self.deprecated_call()

# Verify the result
self.assertEquals(len(warn), 1)
self.assertTrue(issubclass(warn[0].category, DeprecationWarning))
self.assertTrue("This is a deprecation" in str(warn[0].message))
self.assertTrue("x.y.z" in str(warn[0].message))
Loading