Add deprecation warnings (#13927)

This commit is contained in:
Pere Miquel Brull 2023-11-10 10:47:07 +01:00 committed by GitHub
parent 8891a9a410
commit 7c06116b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 0 deletions

View File

@ -30,6 +30,7 @@ from metadata.ingestion.ometa.mixins.patch_mixin_utils import (
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()
@ -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:
@ -54,6 +56,7 @@ class GlossaryMixin(OMetaPatchMixinBase):
)
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:
@ -64,6 +67,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
)
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],
@ -133,6 +140,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
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],
@ -221,6 +232,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
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]],
@ -307,6 +322,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
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],
@ -385,6 +404,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
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],

View File

@ -30,6 +30,7 @@ from metadata.ingestion.ometa.mixins.patch_mixin_utils import (
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()
@ -129,6 +130,10 @@ class OMetaRolePolicyMixin(OMetaPatchMixinBase):
]
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],
@ -261,6 +266,10 @@ class OMetaRolePolicyMixin(OMetaPatchMixinBase):
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],

View File

@ -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

View File

@ -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))