internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: oppia/oppia

Issue:
NotLoggedInException erroneously raised when non-logged-in user clicks the create button in the navbar
Steps to reproduce:
1. Start a new Oppia dev instance.
2. Go to the splash page.
3. Look at the error logs in a terminal, then click on the Create button in the navbar.

Observed:
The error logs show that a self.NotLoggedInException is raised.

Expected:
There should be no such exception thrown, since the user actions constitute a perfectly valid sequence of events.

Note that there is no user-visible effect, but this clutters up the error logs and should be fixed since it may be indicative of other errors.


Discussion:
oh.

Guest user visits the splash page.
The user tries to create an exploration (by clicking on `create` button) but is not logged in. So, exception is raised and user is redirected to login page. (Redirection due to unauthenticated attempt is handled by NotLoggedInException)

It is working as per expected behavior (which I considered). Isn't the normal flow to login after splash page?
The user-visible behavior is correct, but why is the NotLoggedInException being shown as an error in the server logs?

I think the issue is that _handle_exception() is outputting these tracebacks for all exceptions. You probably want to handle the NotLoggedInException case first, then log, then handle the others.

Resolving patch:
diff --git a/core/controllers/base.py b/core/controllers/base.py
--- a/core/controllers/base.py
+++ b/core/controllers/base.py
@@ -434,6 +434,11 @@ def handle_exception(self, exception, unused_debug_mode):
             unused_debug_mode: bool. True if the web application is running
                 in debug mode.
         """
+        if isinstance(exception, self.NotLoggedInException):
+            self.redirect(
+                current_user_services.create_login_url(self.request.uri))
+            return
+
         logging.info(''.join(traceback.format_exception(*sys.exc_info())))
         logging.error('Exception raised: %s', exception)
 
@@ -444,11 +449,6 @@ def handle_exception(self, exception, unused_debug_mode):
                 'error': 'Could not find the page %s.' % self.request.uri})
             return
 
-        if isinstance(exception, self.NotLoggedInException):
-            self.redirect(
-                current_user_services.create_login_url(self.request.uri))
-            return
-
         if isinstance(exception, self.UnauthorizedUserException):
             self.error(401)
             self._render_exception(401, {'error': unicode(exception)})


Test patch:
Repository: oppia/oppia

Issue:
Update directives that use Jinja to directly reference templates
There are some directives that use Jinja and can't be loaded directly by `directiveUrl`. We have two options:
1. Refactor these directives to don't use Jinja
2. Create a backend handler for directives that will parse the Jinja before serving them.

These are the directives:

- [x] components/create_button/create_activity_button_directive.html
- [x] pages/collection_editor/collection_editor_navbar_directive.html
- [x] pages/dashboard/create_activity_modal_directive.html
- [x] pages/exploration_editor/editor_navigation_directive.html
- [x] pages/library/search_results_directive.html


Discussion:

Resolving patch:
diff --git a/core/controllers/base.py b/core/controllers/base.py
--- a/core/controllers/base.py
+++ b/core/controllers/base.py
@@ -327,7 +327,8 @@ def render_template(
             'username': self.username,
             'user_is_logged_in': user_services.has_fully_registered(
                 self.user_id),
-            'preferred_site_language_code': self.preferred_site_language_code
+            'preferred_site_language_code': self.preferred_site_language_code,
+            'allow_yaml_file_upload': feconf.ALLOW_YAML_FILE_UPLOAD
         })
         if feconf.ENABLE_PROMO_BAR:
             promo_bar_enabled = config_domain.PROMO_BAR_ENABLED.value


Test patch:
diff --git a/core/controllers/creator_dashboard_test.py b/core/controllers/creator_dashboard_test.py
--- a/core/controllers/creator_dashboard_test.py
+++ b/core/controllers/creator_dashboard_test.py
@@ -734,18 +734,3 @@ def test_new_exploration_ids(self):
         self.assertEqual(len(exp_a_id), 12)
 
         self.logout()
-
-    def test_exploration_upload_button(self):
-        """Test that the exploration upload button appears when appropriate."""
-        self.login(self.EDITOR_EMAIL)
-
-        response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL)
-        self.assertEqual(response.status_int, 200)
-        response.mustcontain(no=['ng-click="showUploadExplorationModal()"'])
-
-        with self.swap(feconf, 'ALLOW_YAML_FILE_UPLOAD', True):
-            response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL)
-            self.assertEqual(response.status_int, 200)
-            response.mustcontain('ng-click="showUploadExplorationModal()"')
-
-        self.logout()
Repository: oppia/oppia

Issue:
Id generator producing too many collisions on production
On production, clicking on the Create button directly (ie. not logging in and straight from the splash page) produces the following error as shown: 

![ezgif-1-fe4ef88b3e](https://user-images.githubusercontent.com/5758256/29503682-c4452bae-85ee-11e7-82a0-066b997fe4c9.gif)

Please note that the only click was the initial click on the Create button. 

The error does not occur when the user is already logged in and does not occur 100% of the time. It also does not occur on develop in a local environment.


Discussion:
Ooh, that looks odd. Is it reproducible in production? It doesn't happen for me, but I can imagine that this happens sometimes. I seem to remember that @tjiang11 may have seen it too.
Yes
but not 100% of the time.
@kevinlee12 What browser/OS are you using, BTW? It doesn't appear to happen to me (Firefox, Ubuntu)
Hi @AllanYangZhou, I was testing this on Chrome on Ubuntu on oppia.org 

Resolving patch:
diff --git a/core/storage/base_model/gae_models.py b/core/storage/base_model/gae_models.py
--- a/core/storage/base_model/gae_models.py
+++ b/core/storage/base_model/gae_models.py
@@ -29,7 +29,7 @@
 
 # Constants used for generating ids.
 MAX_RETRIES = 10
-RAND_RANGE = 127 * 127
+RAND_RANGE = (1 << 60) - 1
 ID_LENGTH = 12
 
 


Test patch:
Repository: oppia/oppia

Issue:
AssertionError in controllers/base.py
Bug found when doing a sanity testpass on oppiatestserver for the 2.5.4 release.

Steps to reproduce:
- Go to https://oppiatestserver.appspot.com
- Ensure you're logged out
- From the splash screen, click 'Create your own lesson'
- Observe 'Error Communicating with Server' snackbar

Error info:

```
Traceback (most recent call last): (/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/controllers/base.py:438)
  File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/domain/acl_decorators.py", line 247, in test_can_create
    return handler(self, **kwargs)
  File "/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/controllers/creator_dashboard.py", line 279, in post
    new_exploration_id = exp_services.get_new_exploration_id()
  File "/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/domain/exp_services.py", line 325, in get_new_exploration_id
    return exp_models.ExplorationModel.get_new_id('')
  File "/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/storage/base_model/gae_models.py", line 178, in get_new_id
    '%s%s' % (entity_name, utils.get_random_int(RAND_RANGE)),
  File "/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/utils.py", line 218, in get_random_int
    assert upper_bound >= 0 and isinstance(upper_bound, int)
Exception raised:  (/base/data/home/apps/s~oppiatestserver/2-5-4.403832684503391573/core/controllers/base.py:439)
```

This is consistently reproable just by visiting https://oppiatestserver.appspot.com/creator_dashboard?mode=create.


Discussion:
This appears to have been caused by #3799. Based on the assertion in utils.py, this will fail because the new range ``(1 << 60) - 1`` is larger than an int can hold.
This is currently breaking **all** entity creation that generates new IDs, so the site is essentially unusable including both editors and learner views.
This does not repro locally to me; I suspect that app engine is using a 32 bit version of Python, so its integer size must be 32 bits rather than 64 bits. My local environment is fully 64 bit, so the new range fits within allowed sizes for me.

Resolving patch:
diff --git a/core/storage/base_model/gae_models.py b/core/storage/base_model/gae_models.py
--- a/core/storage/base_model/gae_models.py
+++ b/core/storage/base_model/gae_models.py
@@ -29,7 +29,7 @@
 
 # Constants used for generating ids.
 MAX_RETRIES = 10
-RAND_RANGE = (1 << 60) - 1
+RAND_RANGE = (1 << 30) - 1
 ID_LENGTH = 12
 
 


Test patch:
Repository: oppia/oppia

Issue:
Unify the naming of modal directive HTMLs.
1. Rename all HTMLs of directives ending with __modal.html_ to end with __modal_directive.html_
2. After all these directives are renamed, remove '*_modal.html' from FILEPATHS_PROVIDED_TO_FRONTEND in _scripts/build.py_.


Discussion:

Resolving patch:
diff --git a/scripts/build.py b/scripts/build.py
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -61,8 +61,8 @@
 
 # Hashes for files with these paths should be provided to the frontend in
 # JS hashes object.
-FILEPATHS_PROVIDED_TO_FRONTEND = ('images/*', 'i18n/*', '*_directive.html',
-                                  '*_modal.html', '*.png')
+FILEPATHS_PROVIDED_TO_FRONTEND = (
+    'images/*', 'i18n/*', '*_directive.html', '*.png')
 
 HASH_BLOCK_SIZE = 2**20
 


Test patch:
Repository: oppia/oppia

Issue:
Admin role may not be inheriting collection editor access permission
Repro steps:

1. Start local dev server
1. Create local admin account
1. Add admin account to 'admin' role via the admin panel
1. Go to the creator dashboard
1. Click 'Create'

Observed: goes straight into exploration editor

Expected: panel to open up asking whether the user wants to create an exploration or collection

The expected behavior works correctly if in step (3) you instead grant the account the 'collection_editor' role.


Discussion:

Resolving patch:
diff --git a/core/controllers/base.py b/core/controllers/base.py
--- a/core/controllers/base.py
+++ b/core/controllers/base.py
@@ -33,6 +33,7 @@
 from core.domain import config_domain
 from core.domain import config_services
 from core.domain import rights_manager
+from core.domain import role_services
 from core.domain import user_services
 from core.platform import models
 import feconf
@@ -311,11 +312,10 @@ def render_template(
             'INVALID_NAME_CHARS': feconf.INVALID_NAME_CHARS,
             'SITE_FEEDBACK_FORM_URL': feconf.SITE_FEEDBACK_FORM_URL,
             'SITE_NAME': feconf.SITE_NAME,
-
             'SYSTEM_USERNAMES': feconf.SYSTEM_USERNAMES,
             'TEMPLATE_DIR_PREFIX': utils.get_template_dir_prefix(),
             'can_create_collections': bool(
-                self.role == feconf.ROLE_ID_COLLECTION_EDITOR),
+                role_services.ACTION_CREATE_COLLECTION in self.user.actions),
             'username': self.username,
             'user_is_logged_in': user_services.has_fully_registered(
                 self.user_id),


Test patch:
diff --git a/core/tests/protractor/libraryPagesTour.js b/core/tests/protractor/libraryPagesTour.js
--- a/core/tests/protractor/libraryPagesTour.js
+++ b/core/tests/protractor/libraryPagesTour.js
@@ -35,7 +35,7 @@ describe('Library pages tour', function() {
   beforeEach(function() {
     libraryPage = new LibraryPage.LibraryPage();
   });
-  
+
   var visitLibraryPage = function() {
     libraryPage.get();
   };
@@ -51,7 +51,8 @@ describe('Library pages tour', function() {
   it('visits the top rated page', function() {
     // To visit the top rated page, at least one
     // exploration has to be rated by the user
-    users.createAndLoginAdminUser('random@gmail.com', 'random');
+    users.createUser('random@gmail.com', 'random');
+    users.login('random@gmail.com');
     workflow.createAndPublishExploration(
       EXPLORATION_TITLE,
       EXPLORATION_CATEGORY,
Repository: oppia/oppia

Issue:
Error when running ExplorationStateIdMappingJob
When running ``ExplorationStateIdMappingJob`` on the test server after cherrypicking #4157 an error occurs:

```
Traceback (most recent call last): (third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py:508)
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 494, in handle
    tstate.input_reader, shard_state, tstate, ctx)
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 583, in _process_inputs
    entity, input_reader, ctx, tstate):
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 634, in _process_datum
    output_writer.write(output)
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/output_writers.py", line 1145, in write
    if len(data) != 2:
TypeError: object of type 'exceptions.Exception' has no len()
```


Discussion:
/cc @pranavsid98 
/cc @prasanna08 
/cc @seanlip 

Resolving patch:
diff --git a/core/domain/exp_jobs_one_off.py b/core/domain/exp_jobs_one_off.py
--- a/core/domain/exp_jobs_one_off.py
+++ b/core/domain/exp_jobs_one_off.py
@@ -377,7 +377,7 @@ def map(item):
                     exp_services.get_multiple_explorations_by_version(
                         exploration.id, versions))
             except Exception as e:
-                yield e
+                yield ('ERROR with exp_id %s' % item.id, str(e))
                 return
 
         # Append latest exploration to the list of explorations.


Test patch:
Repository: oppia/oppia

Issue:
KeyError when running GenerateV1StatisticsJob with production data
Stack trace:

```
Traceback (most recent call last): (third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py:508)
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 494, in handle
    tstate.input_reader, shard_state, tstate, ctx)
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 583, in _process_inputs
    entity, input_reader, ctx, tstate):
  File "third_party/gae-mapreduce-1.9.17.0/mapreduce/handlers.py", line 625, in _process_datum
    for output in result:
  File "core/domain/stats_jobs_one_off.py", line 351, in reduce
    state_stats_mapping[state_name].total_hit_count_v1 += (
KeyError: u'Introduction   A1'
```


Discussion:

Resolving patch:
diff --git a/core/domain/stats_jobs_one_off.py b/core/domain/stats_jobs_one_off.py
--- a/core/domain/stats_jobs_one_off.py
+++ b/core/domain/stats_jobs_one_off.py
@@ -230,7 +230,9 @@ def reduce(exp_id, stringified_values):
 
                 # Some state names in events have spaces replaced with plus
                 # signs. We explicitly log these for future reference.
-                if '+' in state_name:
+                versioned_exploration = explorations_by_version[version - 1]
+                if '+' in state_name and (
+                        state_name not in versioned_exploration.states):
                     state_name = state_name.replace('+', ' ')
                     value['state_name'] = state_name
                     yield (


Test patch:
diff --git a/core/domain/stats_jobs_one_off_test.py b/core/domain/stats_jobs_one_off_test.py
--- a/core/domain/stats_jobs_one_off_test.py
+++ b/core/domain/stats_jobs_one_off_test.py
@@ -395,3 +395,31 @@ def test_exploration_deletion_is_handled(self):
         # Since exploration is deleted, ExplorationStatsModel instance is not
         # created.
         self.assertEqual(exploration_stats, None)
+
+    def test_state_name_sign_replacement_works(self):
+        # Update exploration to version 2.
+        change_list = [{
+            'cmd': exp_domain.CMD_ADD_STATE,
+            'state_name': u'New + day',
+        }]
+        exp_services.update_exploration(
+            feconf.SYSTEM_COMMITTER_ID, self.exp_id, change_list, '')
+
+        self.exploration = exp_services.get_exploration_by_id(self.exp_id)
+
+        stats_models.StateHitEventLogEntryModel.create(
+            self.exp_id, self.exploration.version, u'New + day',
+            'session_id4', {}, feconf.PLAY_TYPE_NORMAL)
+
+        job_id = stats_jobs_one_off.GenerateV1StatisticsJob.create_new()
+        stats_jobs_one_off.GenerateV1StatisticsJob.enqueue(job_id)
+
+        self.assertEqual(self.count_jobs_in_taskqueue(
+            taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
+        self.process_and_flush_pending_tasks()
+
+        exploration_stats = stats_services.get_exploration_stats_by_id(
+            self.exp_id, self.exploration.version)
+        self.assertEqual(
+            exploration_stats.state_stats_mapping[
+                'New + day'].total_hit_count_v1, 1)
Repository: oppia/oppia

Issue:
The music interaction appears to be broken
Repro steps:

1. Either create a new exploration with music input or play through https://oppiatestserver.appspot.com/explore/16 to card  13
2. Try placing notes on the staff

Observed: no notes appear on the staff, and console errors appear (404s) when trying
Expected: notes should appear and allow the answer to be submitted


Discussion:
Console error observed when playing it:

```
GET https://oppiatestserver.appspot.com/build/extensions/interactions/MusicNotesInput/images/whole_note.png 404 ()
```
/cc @vojtechjelinek -- this seems to be due to the interactions refactor?
Confirming this repros on the local dev server
This does seem to be caused by #4130 (the issue goes away when locally rolling that back)

Resolving patch:
diff --git a/scripts/build.py b/scripts/build.py
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -62,7 +62,7 @@
 # Hashes for files with these paths should be provided to the frontend in
 # JS hashes object.
 FILEPATHS_PROVIDED_TO_FRONTEND = (
-    'images/*', 'i18n/*', '*_directive.html', '*.png')
+    'images/*', 'i18n/*', '*_directive.html', '*.png', '*.json')
 
 HASH_BLOCK_SIZE = 2**20
 


Test patch:
Repository: oppia/oppia

Issue:
Completed collections sometimes have 'null' date
Not sure how I got into this state, but when completing collections on the test server I noticed the date was missing in the learner dashboard (this doesn't seem to affect explorations). See picture:

![completed_collection_null_date](https://user-images.githubusercontent.com/12983742/34083393-26950250-e325-11e7-86c2-c0015e5d2b40.png)



Discussion:

Resolving patch:
diff --git a/core/domain/learner_progress_services.py b/core/domain/learner_progress_services.py
--- a/core/domain/learner_progress_services.py
+++ b/core/domain/learner_progress_services.py
@@ -888,7 +888,7 @@ def get_collection_summary_dicts(collection_summaries):
             'category': collection_summary.category,
             'objective': collection_summary.objective,
             'language_code': collection_summary.language_code,
-            'last_updated': utils.get_time_in_millisecs(
+            'last_updated_msec': utils.get_time_in_millisecs(
                 collection_summary.collection_model_last_updated),
             'created_on': utils.get_time_in_millisecs(
                 collection_summary.collection_model_created_on),


Test patch:
Repository: oppia/oppia

Issue:
Error in `collection_domain.py`
In the file `collection_domain.py` file, there is a syntax error at [Line](https://github.com/oppia/oppia/blob/9a8a19f172eb441980e61fa38748617288724885/core/domain/collection_domain.py#L1154), saying `skill is undefined` inside the [function]( https://github.com/oppia/oppia/blob/develop/core/domain/collection_domain.py#L1151-L1154). There should be a list and the variable should be retrieved from that secondary list.


Discussion:
@yashLadha -- it would be helpful to make your bug report more specific, so that, in theory, anyone else who reads it can reproduce and understand the issue. Thanks.
Now @seanlip 
Yes, that is much better. Thanks!

Resolving patch:
diff --git a/core/domain/collection_domain.py b/core/domain/collection_domain.py
--- a/core/domain/collection_domain.py
+++ b/core/domain/collection_domain.py
@@ -1148,10 +1148,10 @@ def get_skill_id_from_skill_name(self, skill_name):
                 present.
         """
         skill_id = None
-        if any([
-                skill_name == skill.name
-                for skill in self.skills.itervalues()]):
-            skill_id = skill.id
+        for skill in self.skills.itervalues():
+            if skill_name == skill.name:
+                skill_id = skill.id
+                break
         return skill_id
 
     def update_skill(self, skill_id, new_skill_name):


Test patch:
Repository: oppia/oppia

Issue:
Fix a couple of residual comments from #4858
This issue is meant to track the (small) residual comments from https://github.com/oppia/oppia/pull/4858.


Discussion:

Resolving patch:
diff --git a/core/domain/exp_domain.py b/core/domain/exp_domain.py
--- a/core/domain/exp_domain.py
+++ b/core/domain/exp_domain.py
@@ -4054,7 +4054,7 @@ def create_mapping_for_new_version(
             # replaced by an explicit END state through this migration.
             # We account for that change in the state id mapping too.
             if change_dict['cmd'] == 'migrate_states_schema_to_latest_version':
-                psuedo_end_state_name = 'END'
+                pseudo_end_state_name = 'END'
                 if int(change_dict['from_version']) < 2 <= int(
                         change_dict['to_version']):
                     # The explicit end state is created only if there is some
@@ -4063,12 +4063,12 @@ def create_mapping_for_new_version(
                     # called 'END' in the immediate version of the exploration
                     # after migration and no state called 'END' is present
                     # in previous version of exploration.
-                    if (psuedo_end_state_name in (
+                    if (pseudo_end_state_name in (
                             new_exploration.states) and (
-                                psuedo_end_state_name not in (
+                                pseudo_end_state_name not in (
                                     self.state_names_to_ids))):
-                        new_state_names.append(psuedo_end_state_name)
-            if change_dict['cmd'] == CMD_ADD_STATE:
+                        new_state_names.append(pseudo_end_state_name)
+            elif change_dict['cmd'] == CMD_ADD_STATE:
                 new_state_names.append(change_dict['state_name'])
                 assert change_dict['state_name'] not in (
                     state_ids_to_names.values())


Test patch:
Repository: oppia/oppia

Issue:
Make edits to content on fractions landing pages
This issue is a tracking issue for making changes to the fractions landing pages based on the first user studies. This issue is prioritized for the current release.
Make edits to content on fractions landing pages
This issue is a tracking issue for making changes to the fractions landing pages based on the first user studies. This issue is prioritized for the current release.


Discussion:

Resolving patch:
diff --git a/core/controllers/custom_landing_pages.py b/core/controllers/custom_landing_pages.py
--- a/core/controllers/custom_landing_pages.py
+++ b/core/controllers/custom_landing_pages.py
@@ -31,7 +31,7 @@ def get(self):
         viewer_type = self.request.get('viewerType')
 
         if not viewer_type:
-            viewer_type = 'student'
+            viewer_type = 'teacher'
             self.redirect('/fractions?viewerType=%s' % viewer_type)
 
         self.render_template(


Test patch: