Skip to content

Commit

Permalink
Update naming and description of the method
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandarmijat committed May 22, 2024
1 parent 453ac83 commit ab28db7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions rasa_sdk/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def __init__(self) -> None:
self.actions: Dict[Text, Callable] = {}
self._modules: Dict[Text, TimestampModule] = {}
self._loaded: Set[Type[Action]] = set()
self.domain: Dict[Text, Any] = {}
self.domain_digest: Text = ""
self.domain: Dict[Text, Any] = None
self.domain_digest: Text = None

def register_action(self, action: Union[Type[Action], Action]) -> None:
if inspect.isclass(action):
Expand Down Expand Up @@ -399,24 +399,31 @@ def is_domain_digest_valid(self, domain_digest: Text) -> bool:
"""
return bool(self.domain_digest) and self.domain_digest == domain_digest

def get_domain(
def update_and_return_domain(
self, payload: Dict[Text, Any], action_name: Text
) -> Dict[Text, Any]:
"""Retrieve the Domain dictionary.
"""Validate the digest, store the domain if available, and return the domain.
This method returns the proper domain if present, otherwise raises the error.
This method validates the domain digest from the payload.
If the digest is invalid and no domain is provided, an exception is raised.
If domain data is available, it stores the domain and digest.
Finally, it returns the domain.
Args:
payload: request payload containing the Domain data.
action_name: name of the action that should be executed.
payload: Request payload containing the domain data.
action_name: Name of the action that should be executed.
Returns:
The Domain dictionary.
The domain dictionary.
Raises:
ActionMissingDomainException: Invalid digest and no domain data available.
"""
payload_domain = payload.get("domain")
payload_domain_digest = payload.get("domain_digest")

# If digest is invalid (empty or mismatched) and no domain is available - raise the error
# If digest is invalid and no domain is available - raise the error
if (
not self.is_domain_digest_valid(payload_domain_digest)
and not payload_domain
Expand All @@ -440,7 +447,7 @@ async def run(self, action_call: "ActionCall") -> Optional[Dict[Text, Any]]:
raise ActionNotFoundException(action_name)

tracker_json = action_call["tracker"]
domain = self.get_domain(action_call, action_name)
domain = self.update_and_return_domain(action_call, action_name)
tracker = Tracker.from_dict(tracker_json)
dispatcher = CollectingDispatcher()

Expand Down
2 changes: 1 addition & 1 deletion rasa_sdk/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class ActionMissingDomainException(Exception):

def __init__(self, action_name: Text, message: Optional[Text] = None) -> None:
self.action_name = action_name
self.message = message or f"Domain context is missing."
self.message = message or "Domain context is missing."

def __str__(self) -> Text:
return self.message

0 comments on commit ab28db7

Please sign in to comment.