mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-13 09:48:19 +00:00
Add deprecation warnings (#13927)
This commit is contained in:
parent
8891a9a410
commit
7c06116b53
@ -30,6 +30,7 @@ from metadata.ingestion.ometa.mixins.patch_mixin_utils import (
|
|||||||
PatchValue,
|
PatchValue,
|
||||||
)
|
)
|
||||||
from metadata.ingestion.ometa.utils import model_str
|
from metadata.ingestion.ometa.utils import model_str
|
||||||
|
from metadata.utils.deprecation import deprecated
|
||||||
from metadata.utils.logger import ometa_logger
|
from metadata.utils.logger import ometa_logger
|
||||||
|
|
||||||
logger = ometa_logger()
|
logger = ometa_logger()
|
||||||
@ -44,6 +45,7 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
To be inherited by OpenMetadata
|
To be inherited by OpenMetadata
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@deprecated(message="Use metadata.create_or_update instead", release="1.3")
|
||||||
def create_glossary(self, glossaries_body):
|
def create_glossary(self, glossaries_body):
|
||||||
"""Method to create new Glossary
|
"""Method to create new Glossary
|
||||||
Args:
|
Args:
|
||||||
@ -54,6 +56,7 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
)
|
)
|
||||||
logger.info(f"Created a Glossary: {resp}")
|
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):
|
def create_glossary_term(self, glossary_term_body):
|
||||||
"""Method to create new Glossary Term
|
"""Method to create new Glossary Term
|
||||||
Args:
|
Args:
|
||||||
@ -64,6 +67,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
)
|
)
|
||||||
logger.info(f"Created a Glossary Term: {resp}")
|
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(
|
def patch_glossary_term_parent(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
@ -133,6 +140,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
|
|
||||||
return None
|
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(
|
def patch_glossary_term_related_terms(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
@ -221,6 +232,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
|
|
||||||
return None
|
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(
|
def patch_reviewers(
|
||||||
self,
|
self,
|
||||||
entity: Union[Type[Glossary], Type[GlossaryTerm]],
|
entity: Union[Type[Glossary], Type[GlossaryTerm]],
|
||||||
@ -307,6 +322,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
|
|
||||||
return None
|
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(
|
def patch_glossary_term_synonyms(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
@ -385,6 +404,10 @@ class GlossaryMixin(OMetaPatchMixinBase):
|
|||||||
|
|
||||||
return None
|
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(
|
def patch_glossary_term_references(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
|
@ -30,6 +30,7 @@ from metadata.ingestion.ometa.mixins.patch_mixin_utils import (
|
|||||||
PatchValue,
|
PatchValue,
|
||||||
)
|
)
|
||||||
from metadata.ingestion.ometa.utils import model_str
|
from metadata.ingestion.ometa.utils import model_str
|
||||||
|
from metadata.utils.deprecation import deprecated
|
||||||
from metadata.utils.logger import ometa_logger
|
from metadata.utils.logger import ometa_logger
|
||||||
|
|
||||||
logger = ometa_logger()
|
logger = ometa_logger()
|
||||||
@ -129,6 +130,10 @@ class OMetaRolePolicyMixin(OMetaPatchMixinBase):
|
|||||||
]
|
]
|
||||||
return data
|
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(
|
def patch_role_policy(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
@ -261,6 +266,10 @@ class OMetaRolePolicyMixin(OMetaPatchMixinBase):
|
|||||||
|
|
||||||
return None
|
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(
|
def patch_policy_rule(
|
||||||
self,
|
self,
|
||||||
entity_id: Union[str, basic.Uuid],
|
entity_id: Union[str, basic.Uuid],
|
||||||
|
35
ingestion/src/metadata/utils/deprecation.py
Normal file
35
ingestion/src/metadata/utils/deprecation.py
Normal 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
|
39
ingestion/tests/unit/utils/test_deprecation.py
Normal file
39
ingestion/tests/unit/utils/test_deprecation.py
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user