Repository: RasaHQ/rasa
Pull request: [bugfix][WIP] Fix the bug of language supporting detection function of component
**Proposed changes**:
- `supported_langauge_list` and `not_supported_language_list` are not allowed be setted in same time.
- update the implement of `can_handle_language` function

fix #6802

**Status (please check what you already did)**:
- [ ] added some tests for the functionality
- [ ] updated the documentation
- [ ] updated the changelog (please check [changelog](https://github.com/RasaHQ/rasa/tree/master/changelog) for instructions)
- [ ] reformat files using `black` (please check [Readme](https://github.com/RasaHQ/rasa#code-style) for instructions)


Problem statement:
A bug with language supporting detection function of component
**Rasa version**: 2.0.0rc1

**Issue**:

If a new component has such language supporting settings:

```python
supported_language_list = ["en", "xx"]
not_supported_language_list = None  # which is the default value
```
it will not work correctly since the `can_handle_language` function not implemented incorrectly:

```python
        language_list = cls.supported_language_list or []
        not_supported_language_list = cls.not_supported_language_list or []

        return language in language_list or language not in not_supported_language_list
```

since `not_supported_language_list` will be `[]` in our example, so `language not in not_supported_language_list` will always be true no matter what's the value of `language`. Finally when `cls.not_supported_language_list` is None then all language will be supported which is not we wanted.

I will submit a PR to fix it.

Hints from issue discussion:
Thanks for the issue, @erohmensing will get back to you about it soon!

###### You may find help in the [docs](https://rasa.com/docs/) and the [forum,](https://forum.rasa.com/) too 🤗
Thanks for the initiative toward fixing this!

Commit message: add changelog

Patch to review:
diff --git a/changelog/6803.bugfix.md b/changelog/6803.bugfix.md
new file mode 100644
index 000000000000..b547b01568f3
--- /dev/null
+++ b/changelog/6803.bugfix.md
@@ -0,0 +1,3 @@
+Fixed the bug that `supported_language_list` of `component` is not working correctly
+
+To avoid confusion, only one of `supported_language_list` and `not_supported_language_list` can be set to not None now
diff --git a/rasa/nlu/components.py b/rasa/nlu/components.py
index 0b35cf9e5bd8..2e430ea13a8f 100644
--- a/rasa/nlu/components.py
+++ b/rasa/nlu/components.py
@@ -365,13 +365,19 @@ def required_components(cls) -> List[Type["Component"]]:
 
     # Defines what language(s) this component can handle.
     # This attribute is designed for instance method: `can_handle_language`.
-    # Default value is None which means it can handle all languages.
+    # Default value is None. if both `support_language_list` and
+    # `not_supported_language_list` are None, which means it can handle
+    # all languages. Also, only one of `support_language_list` and
+    # `not_supported_language_list` can be set to not None.
     # This is an important feature for backwards compatibility of components.
     supported_language_list = None
 
     # Defines what language(s) this component can NOT handle.
     # This attribute is designed for instance method: `can_handle_language`.
-    # Default value is None which means it can handle all languages.
+    # Default value is None. if both `support_language_list` and
+    # `not_supported_language_list` are None, which means it can handle
+    # all languages. Also, only one of `support_language_list` and
+    # `not_supported_language_list` can be set to not None.
     # This is an important feature for backwards compatibility of components.
     not_supported_language_list = None
 
@@ -629,17 +635,25 @@ def can_handle_language(cls, language: Hashable) -> bool:
             `True` if component can handle specific language, `False` otherwise.
         """
 
-        # if language_list is set to `None` it means: support all languages
+        # If both `supported_language_list` and `not_supported_language_list` are set to `None`,
+        # it means: support all languages
         if language is None or (
             cls.supported_language_list is None
             and cls.not_supported_language_list is None
         ):
             return True
 
-        language_list = cls.supported_language_list or []
-        not_supported_language_list = cls.not_supported_language_list or []
+        # check language supporting settings
+        if cls.supported_language_list and cls.not_supported_language_list:
+            # When user set both language supporting settings to not None, it will lead to ambiguity.
+            raise Exception(
+                "Only one of `supported_language_list` and `not_supported_language_list` can be set to not None"
+            )
 
-        return language in language_list or language not in not_supported_language_list
+        if cls.supported_language_list:
+            return language in cls.supported_language_list
+        else:
+            return language not in cls.not_supported_language_list
 
 
 C = typing.TypeVar("C", bound=Component)


Code review comments:
diff_hunk: @@ -629,17 +635,25 @@ def can_handle_language(cls, language: Hashable) -> bool:
             `True` if component can handle specific language, `False` otherwise.
         """
 
-        # if language_list is set to `None` it means: support all languages
+        # If both `supported_language_list` and `not_supported_language_list` are set to `None`,
+        # it means: support all languages
         if language is None or (
             cls.supported_language_list is None
             and cls.not_supported_language_list is None
         ):
             return True
 
-        language_list = cls.supported_language_list or []
-        not_supported_language_list = cls.not_supported_language_list or []
+        # check language supporting settings
+        if cls.supported_language_list and cls.not_supported_language_list:
+            # When user set both language supporting settings to not None, it will lead to ambiguity.
+            raise Exception(
+                "Only one of `supported_language_list` and `not_supported_language_list` can be set to not None"
+            )
 
-        return language in language_list or language not in not_supported_language_list
+        if cls.supported_language_list:
+            return language in cls.supported_language_list
+        else:
+            return language not in cls.not_supported_language_list
path: rasa/nlu/components.py
text: @user1:
This check will result in a runtime exception if `not_supported_language_list` was set to `[]` and `supported_language_list` was `None`. I know that is not really something someone would set, but we can catch the case by either - 
1. changing `else` construct with `elif cls.not_supported_language_list` or
2. Turning both `cls.supported_language_list` and `cls.not_supported_language_list` to empty lists if they are none and then proceeding with the above `if` constructs.

@author:
I add some guard clause for this in a later commit.