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

Cleanup deprecation warnings #6453

Merged
merged 25 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b3ba78f
remove deprecations from 1.x
m-vdb Aug 19, 2020
67de788
raise_deprecation_warning() utils requires warn_until_version
m-vdb Aug 19, 2020
b488e69
remove another deprecation warning in rasa.core.domain
m-vdb Aug 19, 2020
552e122
raise deprecation warning for Mattermost channel until 3.0.0
m-vdb Aug 19, 2020
b42d12e
use raise_deprecation_warning() in tracker_store.py
m-vdb Aug 21, 2020
aebd37a
Merge branch 'master' into remove-deprecation-warnings
m-vdb Aug 21, 2020
9dd4046
use FutureWarning and the correct stacklevel
m-vdb Aug 21, 2020
50477f5
add unit tests + a better comment
m-vdb Aug 21, 2020
ea72154
add changelog fragment for removals
m-vdb Aug 21, 2020
4d18f08
more cleanup in PikaEventBroker
m-vdb Aug 21, 2020
2f8483d
_replace_deprecated_option() uses raise_deprecation_warning()
m-vdb Aug 21, 2020
cd9088d
fix tests
m-vdb Aug 21, 2020
08b8bfb
fix validator and tracker store tests
m-vdb Aug 21, 2020
de97ed5
Merge branch 'master' into remove-deprecation-warnings
m-vdb Aug 21, 2020
a487fa2
do responses validation using yaml schema
m-vdb Aug 24, 2020
76b4376
Merge branch 'master' into remove-deprecation-warnings
m-vdb Aug 25, 2020
a546cd9
provide nice defaults for raise_deprecation_warning()
m-vdb Aug 25, 2020
6dda8c4
fix schema definitions
m-vdb Aug 25, 2020
f3c942f
reset nlu schema, no need to have the full response definition
m-vdb Aug 25, 2020
d938060
implement custom validation of response keys
m-vdb Aug 25, 2020
4aafccc
Merge branch 'master' into remove-deprecation-warnings
m-vdb Aug 25, 2020
f8d370a
remove support for custom keys
m-vdb Aug 25, 2020
4ab94c7
define responses schema in schemas/nlu.yml
m-vdb Aug 26, 2020
f9ea0f3
Merge branch 'master' into remove-deprecation-warnings
m-vdb Aug 26, 2020
f04ec88
update changelog fragment to reference documentation pages
m-vdb Aug 26, 2020
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
34 changes: 34 additions & 0 deletions changelog/6453.removal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Removed support for `queue` argument in `PikaEventBroker` (use `queues` instead).

Domain file:
- Removed support for `templates` key (use `responses` instead).
- Removed support for string `responses` (use dictionaries instead).

NLU `Component`:
- Removed support for `provides` attribute, it's not needed anymore.
- Removed support for `requires` attribute (use `required_components()` instead).

Removed `_guess_format()` utils method from `rasa.nlu.training_data.loading` (use `guess_format` instead).

Removed several config options:
- `hidden_layers_sizes_pre_dial`
- `hidden_layers_sizes_bot`
- `droprate`
- `droprate_a`
- `droprate_b`
- `hidden_layers_sizes_a`
- `hidden_layers_sizes_b`
- `num_transformer_layers`
- `num_heads`
- `dense_dim`
- `embed_dim`
- `num_neg`
- `mu_pos`
- `mu_neg`
- `use_max_sim_neg`
- `C2`
- `C_emb`
- `evaluate_every_num_epochs`
- `evaluate_on_num_examples`

Please check the documentation for more information.
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 5 additions & 24 deletions rasa/core/brokers/pika.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __init__(
self.password = password
self.port = port
self.channel: Optional["Channel"] = None
self.queues = self._get_queues_from_args(queues, kwargs)
self.queues = self._get_queues_from_args(queues)
self.should_keep_unpublished_messages = should_keep_unpublished_messages
self.raise_on_failure = raise_on_failure

Expand All @@ -315,37 +315,24 @@ def rasa_environment(self) -> Optional[Text]:

@staticmethod
def _get_queues_from_args(
queues_arg: Union[List[Text], Tuple[Text], Text, None], kwargs: Any
queues_arg: Union[List[Text], Tuple[Text], Text, None]
) -> Union[List[Text], Tuple[Text]]:
"""Get queues for this event broker.

The preferred argument defining the RabbitMQ queues the `PikaEventBroker` should
publish to is `queues` (as of Rasa Open Source version 1.8.2). This function
ensures backwards compatibility with the old `queue` argument. This method
publish to is `queues` (as of Rasa Open Source version 1.8.2). This method
can be removed in the future, and `self.queues` should just receive the value of
the `queues` kwarg in the constructor.

Args:
queues_arg: Value of the supplied `queues` argument.
kwargs: Additional kwargs supplied to the `PikaEventBroker` constructor.
If `queues_arg` is not supplied, the `queue` kwarg will be used instead.

Returns:
Queues this event broker publishes to.

Raises:
`ValueError` if no valid `queue` or `queues` argument was found.
`ValueError` if no valid `queues` argument was found.
"""
queue_arg = kwargs.pop("queue", None)

if queue_arg:
raise_warning(
"Your Pika event broker config contains the deprecated `queue` key. "
"Please use the `queues` key instead.",
FutureWarning,
docs=DOCS_URL_PIKA_EVENT_BROKER,
)

if queues_arg and isinstance(queues_arg, (list, tuple)):
return queues_arg

Expand All @@ -357,14 +344,8 @@ def _get_queues_from_args(
)
return [queues_arg]

if queue_arg and isinstance(queue_arg, str):
return [queue_arg]

if queue_arg:
return queue_arg # pytype: disable=bad-return-type

raise_warning(
f"No `queues` or `queue` argument provided. It is suggested to "
f"No `queues` argument provided. It is suggested to "
f"explicitly specify a queue as described in "
f"{DOCS_URL_PIKA_EVENT_BROKER}. "
f"Using the default queue '{DEFAULT_QUEUE_NAME}' for now."
Expand Down
6 changes: 3 additions & 3 deletions rasa/core/channels/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rasa.core.channels.channel import UserMessage, OutputChannel, InputChannel
from sanic.response import HTTPResponse

from rasa.utils.common import raise_warning
from rasa.utils import common as common_utils

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -132,12 +132,12 @@ def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChanne

# pytype: disable=attribute-error
if credentials.get("pw") is not None or credentials.get("user") is not None:
raise_warning(
common_utils.raise_deprecation_warning(
"Mattermost recently switched to bot accounts. 'user' and 'pw' "
"should not be used anymore, you should rather convert your "
"account to a bot account and use a token. Password based "
"authentication will be removed in a future Rasa Open Source version.",
FutureWarning,
warn_until_version="3.0.0",
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
docs=DOCS_URL_CONNECTORS + "mattermost/",
)
token = MattermostBot.token_from_login(
Expand Down
22 changes: 3 additions & 19 deletions rasa/core/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@ def from_yaml(cls, yaml: Text, original_filename: Text = "") -> "Domain":
@classmethod
def from_dict(cls, data: Dict) -> "Domain":
utter_templates = cls.collect_templates(data.get(KEY_RESPONSES, {}))
if "templates" in data:
raise_warning(
"Your domain file contains the key: 'templates'. This has been "
"deprecated and renamed to 'responses'. The 'templates' key will "
"no longer work in future versions of Rasa. Please replace "
"'templates' with 'responses'",
FutureWarning,
docs=DOCS_URL_DOMAINS,
)
utter_templates = cls.collect_templates(data.get("templates", {}))

slots = cls.collect_slots(data.get(KEY_SLOTS, {}))
additional_arguments = data.get("config", {})
session_config = cls._get_session_config(data.get(SESSION_CONFIG_KEY, {}))
Expand Down Expand Up @@ -432,17 +421,12 @@ def collect_templates(

for t in template_variations:

# responses should be a dict with options
if isinstance(t, str):
raise_warning(
f"Responses should not be strings anymore. "
if not isinstance(t, dict):
raise InvalidDomain(
f"Response '{template_key}' should contain "
f"either a '- text: ' or a '- custom: ' "
f"attribute to be a proper response.",
FutureWarning,
docs=DOCS_URL_DOMAINS + "#responses",
f"attribute to be a proper response."
)
validated_variations.append({"text": t})
elif "text" not in t and "custom" not in t:
raise InvalidDomain(
f"Response '{template_key}' needs to contain either "
Expand Down
4 changes: 2 additions & 2 deletions rasa/core/policies/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def __init__(
self.core_threshold = core_threshold
self.fallback_action_name = fallback_action_name

common_utils.raise_warning(
common_utils.raise_deprecation_warning(
f"'{self.__class__.__name__}' is deprecated and will be removed "
"in the future. It is recommended to use the 'RulePolicy' instead.",
category=FutureWarning,
warn_until_version="3.0.0",
docs=DOCS_URL_MIGRATION_GUIDE,
)

Expand Down
4 changes: 2 additions & 2 deletions rasa/core/policies/form_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def __init__(
featurizer=featurizer, priority=priority, max_history=2, lookup=lookup
)

common_utils.raise_warning(
common_utils.raise_deprecation_warning(
f"'{FormPolicy.__name__}' is deprecated and will be removed in "
"in the future. It is recommended to use the 'RulePolicy' instead.",
category=FutureWarning,
warn_until_version="3.0.0",
docs=DOCS_URL_MIGRATION_GUIDE,
)

Expand Down
4 changes: 2 additions & 2 deletions rasa/core/policies/mapping_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def __init__(self, priority: int = MAPPING_POLICY_PRIORITY) -> None:

super().__init__(priority=priority)

common_utils.raise_warning(
common_utils.raise_deprecation_warning(
f"'{MappingPolicy.__name__}' is deprecated and will be removed in "
"the future. It is recommended to use the 'RulePolicy' instead.",
category=FutureWarning,
warn_until_version="3.0.0",
docs=DOCS_URL_MIGRATION_GUIDE,
)

Expand Down
15 changes: 8 additions & 7 deletions rasa/core/tracker_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from rasa.core.trackers import ActionExecuted, DialogueStateTracker, EventVerbosity
import rasa.cli.utils as rasa_cli_utils
from rasa.nlu.constants import INTENT_NAME_KEY
from rasa.utils.common import class_from_module_path, raise_warning, arguments_of
from rasa.utils import common as common_utils
from rasa.utils.endpoints import EndpointConfig
import sqlalchemy as sa

Expand Down Expand Up @@ -186,11 +186,12 @@ def _deserialise_dialogue_from_pickle(
sender_id: Text, serialised_tracker: bytes
) -> Dialogue:

logger.warning(
common_utils.raise_deprecation_warning(
f"Found pickled tracker for "
f"conversation ID '{sender_id}'. Deserialisation of pickled "
f"trackers will be deprecated in version 2.0. Rasa will perform any "
f"future save operations of this tracker using json serialisation."
f"trackers is deprecated. Rasa will perform any "
f"future save operations of this tracker using json serialisation.",
warn_until_version="3.0.0",
)
return pickle.loads(serialised_tracker)

Expand Down Expand Up @@ -1086,8 +1087,8 @@ def _load_from_module_name_in_endpoint_config(
"""

try:
tracker_store_class = class_from_module_path(store.type)
init_args = arguments_of(tracker_store_class.__init__)
tracker_store_class = common_utils.class_from_module_path(store.type)
init_args = common_utils.arguments_of(tracker_store_class.__init__)
if "url" in init_args and "host" not in init_args:
# DEPRECATION EXCEPTION - remove in 2.1
raise Exception(
Expand All @@ -1102,7 +1103,7 @@ def _load_from_module_name_in_endpoint_config(
domain=domain, event_broker=event_broker, **store.kwargs
)
except (AttributeError, ImportError):
raise_warning(
common_utils.raise_warning(
f"Tracker store with type '{store.type}' not found. "
f"Using `InMemoryTrackerStore` instead."
)
Expand Down
28 changes: 0 additions & 28 deletions rasa/nlu/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import typing
from typing import Any, Dict, Hashable, List, Optional, Set, Text, Tuple, Type, Iterable

from rasa.constants import DOCS_URL_MIGRATION_GUIDE
from rasa.nlu.constants import TRAINABLE_EXTRACTORS
from rasa.nlu.config import RasaNLUModelConfig, override_defaults, InvalidConfigError
from rasa.nlu.training_data import Message, TrainingData
Expand Down Expand Up @@ -121,32 +120,6 @@ def _required_component_in_pipeline(
return False


def _check_deprecated_attributes(component: "Component") -> None:
"""Checks that the component doesn't have deprecated attributes.

Args:
component: The :class:`rasa.nlu.components.Component`.
"""

if hasattr(component, "provides"):
raise_warning(
f"'{component.name}' contains property 'provides', "
f"which is deprecated. There is no need to specify "
f"the list of attributes that a component provides.",
category=FutureWarning,
docs=DOCS_URL_MIGRATION_GUIDE,
)
if hasattr(component, "requires"):
raise_warning(
f"'{component.name}' contains property 'requires', "
f"which is deprecated. Use 'required_components()' method "
f"to specify which components are required to be present "
f"in the pipeline by this component.",
category=FutureWarning,
docs=DOCS_URL_MIGRATION_GUIDE,
)


def validate_required_components(pipeline: List["Component"]) -> None:
"""Validates that all required components are present in the pipeline.

Expand All @@ -155,7 +128,6 @@ def validate_required_components(pipeline: List["Component"]) -> None:
"""

for i, component in enumerate(pipeline):
_check_deprecated_attributes(component)

missing_components = []
for required_component in component.required_components():
Expand Down
15 changes: 0 additions & 15 deletions rasa/nlu/training_data/formats/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def __init__(self) -> None:
self.regex_features = []
self.lookup_tables = []

self._deprecated_synonym_format_was_used = False

def reads(self, s: Text, **kwargs: Any) -> "TrainingData":
"""Read markdown string and create TrainingData object"""
from rasa.nlu.training_data import TrainingData
Expand All @@ -65,19 +63,6 @@ def reads(self, s: Text, **kwargs: Any) -> "TrainingData":
self._parse_item(line)
self._load_files(line)

if self._deprecated_synonym_format_was_used:
raise_warning(
"You are using the deprecated training data format to declare synonyms."
" Please use the following format: \n"
'[<entity-text>]{"entity": "<entity-type>", "value": '
'"<entity-synonym>"}.'
"\nYou can use the following command to update your training data file:"
"\nsed -i -E 's/\\[([^)]+)\\]\\(([^)]+):([^)]+)\\)/[\\1]{"
'"entity": "\\2", "value": "\\3"}/g\' nlu.md',
category=FutureWarning,
docs=DOCS_URL_TRAINING_DATA_NLU,
)

erohmensing marked this conversation as resolved.
Show resolved Hide resolved
return TrainingData(
self.training_examples,
self.entity_synonyms,
Expand Down
8 changes: 0 additions & 8 deletions rasa/nlu/training_data/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,3 @@ def guess_format(filename: Text) -> Text:
logger.debug(f"Training data format of '{filename}' is '{guess}'.")

return guess


def _guess_format(filename: Text) -> Text:
logger.warning(
"Using '_guess_format()' is deprecated since Rasa 1.1.5. "
"Please use 'guess_format()' instead."
)
return guess_format(filename)
4 changes: 2 additions & 2 deletions rasa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,11 @@ def _validate_json_training_payload(rjs: Dict):
)

if "force" in rjs or "save_to_default_model_directory" in rjs:
common_utils.raise_warning(
common_utils.raise_deprecation_warning(
"Specifying 'force' and 'save_to_default_model_directory' as part of the "
"JSON payload is deprecated. Please use the header arguments "
"'force_training' and 'save_to_default_model_directory'.",
category=FutureWarning,
warn_until_version="3.0.0",
docs=_docs("/api/http-api"),
)

Expand Down
19 changes: 19 additions & 0 deletions rasa/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,25 @@ def formatwarning(
warnings.formatwarning = original_formatter


def raise_deprecation_warning(
message: Text, warn_until_version: Text, docs: Optional[Text] = None, **kwargs: Any,
) -> None:
"""
Thin wrapper around `raise_warning()` to raise a deprecation warning. It requires
a version until which we'll warn, and after which the support for the feature will
be removed.
"""
if warn_until_version not in message:
message = f"{message} (will be removed in {warn_until_version})"

# need the correct stacklevel now
kwargs.setdefault("stacklevel", 3)
# we're raising a `FutureWarning` instead of a `DeprecationWarning` because
# we want these warnings to be visible in the terminal of our users
# https://docs.python.org/3/library/warnings.html#warning-categories
raise_warning(message, FutureWarning, docs, **kwargs)


class RepeatedLogFilter(logging.Filter):
"""Filter repeated log records."""

Expand Down
Loading