Repository: oppia/oppia

Issue:
[Contributor Dashboard] Not able to submit question suggestions on main Oppia server
Screenshot:

![error communicating with server](https://user-images.githubusercontent.com/9004726/109553398-fd6bf980-7aa0-11eb-9464-28c025eb3ea1.png)

Related stack trace for a POST to /suggestionhandler/:

```
Traceback (most recent call last): (/core/controllers/base.py:477)
  File "/third_party/python_libs/webapp2.py", line 604, in dispatch
    return method(*args, **kwargs)
  File "/core/controllers/acl_decorators.py", line 1230, in test_can_suggest
    return handler(self, **kwargs)
  File "/core/controllers/suggestion.py", line 101, in post
    self.payload.get('description'))
  File "/core/domain/suggestion_services.py", line 91, in create_suggestion
    DEFAULT_SUGGESTION_THREAD_INITIAL_MESSAGE, has_suggestion=True)
  File "/core/domain/feedback_services.py", line 122, in create_thread
    has_suggestion)
  File "/core/domain/feedback_services.py", line 99, in _create_models_for_thread_and_first_message
    subject, text)
  File "/core/domain/feedback_services.py", line 153, in create_message
    received_via_email=received_via_email)[0]
  File "/core/domain/feedback_services.py", line 319, in create_messages
    len(text), old_statuses[index], new_statuses[index])
  File "/core/domain/feedback_services.py", line 1145, in _add_message_to_email_buffer
    _get_all_recipient_ids(exploration_id, thread_id, author_id))
  File "/core/domain/feedback_services.py", line 1012, in _get_all_recipient_ids
    exploration_rights = rights_manager.get_exploration_rights(exploration_id)
  File "/core/domain/rights_manager.py", line 228, in get_exploration_rights
    exploration_id, strict=strict)
  File "/core/storage/base_model/gae_models.py", line 1156, in get
    return super(VersionedModel, cls).get(entity_id, strict=strict)
  File "/core/storage/base_model/gae_models.py", line 243, in get
    (cls.__name__, entity_id))
EntityNotFoundError: Entity for class ExplorationRightsModel with id 5UeFU80Yoaf7 not found
```

ID 5UeFU80Yoaf7 refers to a skill in Place Values.
[Contributor Dashboard] Not able to submit question suggestions on main Oppia server
Screenshot:

![error communicating with server](https://user-images.githubusercontent.com/9004726/109553398-fd6bf980-7aa0-11eb-9464-28c025eb3ea1.png)

Related stack trace for a POST to /suggestionhandler/:

```
Traceback (most recent call last): (/core/controllers/base.py:477)
  File "/third_party/python_libs/webapp2.py", line 604, in dispatch
    return method(*args, **kwargs)
  File "/core/controllers/acl_decorators.py", line 1230, in test_can_suggest
    return handler(self, **kwargs)
  File "/core/controllers/suggestion.py", line 101, in post
    self.payload.get('description'))
  File "/core/domain/suggestion_services.py", line 91, in create_suggestion
    DEFAULT_SUGGESTION_THREAD_INITIAL_MESSAGE, has_suggestion=True)
  File "/core/domain/feedback_services.py", line 122, in create_thread
    has_suggestion)
  File "/core/domain/feedback_services.py", line 99, in _create_models_for_thread_and_first_message
    subject, text)
  File "/core/domain/feedback_services.py", line 153, in create_message
    received_via_email=received_via_email)[0]
  File "/core/domain/feedback_services.py", line 319, in create_messages
    len(text), old_statuses[index], new_statuses[index])
  File "/core/domain/feedback_services.py", line 1145, in _add_message_to_email_buffer
    _get_all_recipient_ids(exploration_id, thread_id, author_id))
  File "/core/domain/feedback_services.py", line 1012, in _get_all_recipient_ids
    exploration_rights = rights_manager.get_exploration_rights(exploration_id)
  File "/core/domain/rights_manager.py", line 228, in get_exploration_rights
    exploration_id, strict=strict)
  File "/core/storage/base_model/gae_models.py", line 1156, in get
    return super(VersionedModel, cls).get(entity_id, strict=strict)
  File "/core/storage/base_model/gae_models.py", line 243, in get
    (cls.__name__, entity_id))
EntityNotFoundError: Entity for class ExplorationRightsModel with id 5UeFU80Yoaf7 not found
```

ID 5UeFU80Yoaf7 refers to a skill in Place Values.


Discussion:
Upon initial investigation, it seems the issue is due to an assumption being made when sending feedback thread emails when submitting a suggestion. In `_add_message_to_email_buffer` of `feedback_services.py`, the thread entity (the suggestion target entity) is assumed to be an exploration, but it will be a skill in the case of a question suggestion. These changes were made in https://github.com/oppia/oppia/pull/10022.

This bug was likely not caught during release testing as email notifications have to be enabled for this codepath.
Aha! Great find, and yup, that explains why we couldn't repro on test server. /cc @U8NWXD @nithusha21 @vojtechjelinek for info since it suggests we might need to update our QA process to catch things like this.
@nithusha21 What do the feedback thread emails look like? Is there documentation for them?
I think almost all email templates are in core/domain/email_manager.py
Upon initial investigation, it seems the issue is due to an assumption being made when sending feedback thread emails when submitting a suggestion. In `_add_message_to_email_buffer` of `feedback_services.py`, the thread entity (the suggestion target entity) is assumed to be an exploration, but it will be a skill in the case of a question suggestion. These changes were made in https://github.com/oppia/oppia/pull/10022.

This bug was likely not caught during release testing as email notifications have to be enabled for this codepath.
Aha! Great find, and yup, that explains why we couldn't repro on test server. /cc @U8NWXD @nithusha21 @vojtechjelinek for info since it suggests we might need to update our QA process to catch things like this.
@nithusha21 What do the feedback thread emails look like? Is there documentation for them?
I think almost all email templates are in core/domain/email_manager.py

Resolving patch:
diff --git a/core/domain/feedback_services.py b/core/domain/feedback_services.py
--- a/core/domain/feedback_services.py
+++ b/core/domain/feedback_services.py
@@ -312,7 +312,10 @@ def create_messages(
 
     if (feconf.CAN_SEND_EMAILS and (
             feconf.CAN_SEND_FEEDBACK_MESSAGE_EMAILS and
-            user_services.is_user_registered(author_id))):
+            user_services.is_user_registered(author_id)) and
+            # TODO(#12079): Figure out a better way to avoid sending feedback
+            # thread emails for contributor dashboard suggestions.
+            (len(text) > 0 or old_statuses[index] != new_statuses[index])):
         for index, thread_model in enumerate(thread_models):
             _add_message_to_email_buffer(
                 author_id, thread_model.id, message_ids[index],


Test patch: