Skip to content

Commit

Permalink
Merge pull request #7711 from RasaHQ/prepare-release-2.2.5
Browse files Browse the repository at this point in the history
Prepare release 2.2.5
  • Loading branch information
rasabot committed Jan 12, 2021
2 parents 047b474 + 9d398e1 commit c71c18c
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 77 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.mdx
Expand Up @@ -16,6 +16,16 @@ https://github.com/RasaHQ/rasa/tree/master/changelog/ . -->

<!-- TOWNCRIER -->

## [2.2.5] - 2021-01-12


### Bugfixes
- [#7603](https://github.com/rasahq/rasa/issues/7603): Fixed key-error bug on `rasa data validate stories`.

### Miscellaneous internal changes
- [#7711](https://github.com/rasahq/rasa/issues/7711)


## [2.2.4] - 2021-01-08


Expand Down
1 change: 0 additions & 1 deletion changelog/7603.bugfix.md

This file was deleted.

137 changes: 70 additions & 67 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -9,7 +9,7 @@ exclude = "((.eggs | .git | .pytest_cache | build | dist))"

[tool.poetry]
name = "rasa"
version = "2.2.4"
version = "2.2.5"
description = "Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants"
authors = [ "Rasa Technologies GmbH <hi@rasa.com>",]
maintainers = [ "Tom Bocklisch <tom@rasa.com>",]
Expand Down Expand Up @@ -98,7 +98,7 @@ colorclass = "~2.2"
terminaltables = "~3.1.0"
sanic = ">=19.12.2,<21.0.0"
sanic-cors = "^0.10.0b1"
sanic-jwt = ">=1.3.2,<1.5.0"
sanic-jwt = ">=1.3.2,<2.0"
cloudpickle = ">=1.2,<1.5"
multidict = "^4.6"
aiohttp = "~3.6"
Expand Down
20 changes: 15 additions & 5 deletions rasa/server.py
Expand Up @@ -32,6 +32,7 @@

import rasa
import rasa.core.utils
import rasa.utils.common
import rasa.shared.utils.common
import rasa.shared.utils.io
import rasa.utils.endpoints
Expand Down Expand Up @@ -170,8 +171,14 @@ def conversation_id_from_args(args: Any, kwargs: Any) -> Optional[Text]:
except ValueError:
return None

def sufficient_scope(request, *args: Any, **kwargs: Any) -> Optional[bool]:
jwt_data = request.app.auth.extract_payload(request)
async def sufficient_scope(
request, *args: Any, **kwargs: Any
) -> Optional[bool]:
# This is a coroutine since `sanic-jwt==1.6`
jwt_data = await rasa.utils.common.call_potential_coroutine(
request.app.auth.extract_payload(request)
)

user = jwt_data.get("user", {})

username = user.get("username", None)
Expand All @@ -196,10 +203,13 @@ async def decorated(request: Request, *args: Any, **kwargs: Any) -> Any:
if isawaitable(result):
result = await result
return result
elif app.config.get("USE_JWT") and request.app.auth.is_authenticated(
request
elif app.config.get(
"USE_JWT"
) and await rasa.utils.common.call_potential_coroutine(
# This is a coroutine since `sanic-jwt==1.6`
request.app.auth.is_authenticated(request)
):
if sufficient_scope(request, *args, **kwargs):
if await sufficient_scope(request, *args, **kwargs):
result = f(request, *args, **kwargs)
if isawaitable(result):
result = await result
Expand Down
20 changes: 19 additions & 1 deletion rasa/utils/common.py
Expand Up @@ -4,7 +4,7 @@
import shutil
import warnings
from types import TracebackType
from typing import Any, Coroutine, Dict, List, Optional, Text, Type, TypeVar
from typing import Any, Coroutine, Dict, List, Optional, Text, Type, TypeVar, Union

import rasa.core.utils
import rasa.utils.io
Expand Down Expand Up @@ -312,3 +312,21 @@ def run_in_loop(
loop.run_until_complete(asyncio.gather(*pending))

return result


async def call_potential_coroutine(
coroutine_or_return_value: Union[Any, Coroutine]
) -> Any:
"""Awaits coroutine or returns value directly if it's not a coroutine.
Args:
coroutine_or_return_value: Either the return value of a synchronous function
call or a coroutine which needs to be await first.
Returns:
The return value of the function.
"""
if asyncio.iscoroutine(coroutine_or_return_value):
return await coroutine_or_return_value

return coroutine_or_return_value
2 changes: 1 addition & 1 deletion rasa/version.py
@@ -1,3 +1,3 @@
# this file will automatically be changed,
# do not add anything but the version number here!
__version__ = "2.2.4"
__version__ = "2.2.5"
24 changes: 24 additions & 0 deletions tests/utils/test_common.py
@@ -1,5 +1,7 @@
import logging
from typing import Any

import rasa.utils.common
from rasa.utils.common import RepeatedLogFilter


Expand All @@ -22,3 +24,25 @@ def test_repeated_log_filter():
assert log_filter.filter(record2_other_args) is True
assert log_filter.filter(record3_other) is True
assert log_filter.filter(record1) is True # same as before, but not repeated


async def test_call_maybe_coroutine_with_async() -> Any:
expected = 5

async def my_function():
return expected

actual = await rasa.utils.common.call_potential_coroutine(my_function())

assert actual == expected


async def test_call_maybe_coroutine_with_sync() -> Any:
expected = 5

def my_function():
return expected

actual = await rasa.utils.common.call_potential_coroutine(my_function())

assert actual == expected

0 comments on commit c71c18c

Please sign in to comment.