Repository: oppia/oppia

Issue:
Fix property ordering logic in extend_index_yaml script
The `extend_index_yaml` script seems to be sorting the order of property names in the index YAML files based on this:

https://github.com/oppia/oppia/blob/d4b06399ad2859df6917c5e18ce9024e452351d0/scripts/extend_index_yaml.py#L46-L65

This needs to be changed such that the order of property names remaing unchanged. This is because their order matters (see https://cloud.google.com/appengine/docs/legacy/standard/python/config/indexref#index_definitions.)

Refer https://github.com/oppia/oppia/pull/15967#discussion_r958396543 for more information.
Fix property ordering logic in extend_index_yaml script
The `extend_index_yaml` script seems to be sorting the order of property names in the index YAML files based on this:

https://github.com/oppia/oppia/blob/d4b06399ad2859df6917c5e18ce9024e452351d0/scripts/extend_index_yaml.py#L46-L65

This needs to be changed such that the order of property names remaing unchanged. This is because their order matters (see https://cloud.google.com/appengine/docs/legacy/standard/python/config/indexref#index_definitions.)

Refer https://github.com/oppia/oppia/pull/15967#discussion_r958396543 for more information.


Discussion:

Resolving patch:
diff --git a/scripts/extend_index_yaml.py b/scripts/extend_index_yaml.py
--- a/scripts/extend_index_yaml.py
+++ b/scripts/extend_index_yaml.py
@@ -22,7 +22,6 @@
 
 from __future__ import annotations
 
-import copy
 import os
 
 import yaml
@@ -43,26 +42,10 @@ def main() -> None:
     if web_inf_index_yaml_dict['indexes'] is None:
         return
 
-    # There is a possibility that an index in index.yaml may exist in
-    # ../cloud_datastore_emulator_cache/WEB-INF/index.yaml with different
-    # order of properties. We don't need to append those indexes. So we will
-    # compare sorted dictionaries. Deepcopy is used here to avoid changing the
-    # order of index_yaml_dict after sorting temp_index_yaml_dict.
-    temp_index_yaml_dict = copy.deepcopy(index_yaml_dict)
-    for kind in temp_index_yaml_dict['indexes']:
-        kind['properties'] = sorted(
-            kind['properties'], key=lambda x: x['name']
-    )
-
-    new_kinds = []
-    for kind in web_inf_index_yaml_dict['indexes']:
-        # Deepcopy is used here to avoid changing the order of kind in
-        # temp_index_yaml_dict after sorting temp_web_inf_kind.
-        temp_web_inf_kind = copy.deepcopy(kind)
-        temp_web_inf_kind['properties'] = sorted(
-            temp_web_inf_kind['properties'], key=lambda x: x['name'])
-        if temp_web_inf_kind not in temp_index_yaml_dict['indexes']:
-            new_kinds.append(kind)
+    new_kinds = [
+        kind for kind in web_inf_index_yaml_dict['indexes']
+        if kind not in index_yaml_dict['indexes']
+    ]
 
     if len(new_kinds) == 0:
         return
diff --git a/scripts/run_mypy_checks.py b/scripts/run_mypy_checks.py
--- a/scripts/run_mypy_checks.py
+++ b/scripts/run_mypy_checks.py
@@ -57,8 +57,6 @@
     'scripts/concurrent_task_utils_test.py',
     'scripts/docstrings_checker.py',
     'scripts/docstrings_checker_test.py',
-    'scripts/extend_index_yaml.py',
-    'scripts/extend_index_yaml_test.py',
     'scripts/flake_checker.py',
     'scripts/flake_checker_test.py',
     'scripts/install_python_prod_dependencies.py',


Test patch:
diff --git a/scripts/extend_index_yaml_test.py b/scripts/extend_index_yaml_test.py
--- a/scripts/extend_index_yaml_test.py
+++ b/scripts/extend_index_yaml_test.py
@@ -48,8 +48,8 @@ def setUp(self) -> None:
             self.web_inf_index_yaml_file.name, 'a', encoding='utf-8')
 
     def _run_test_for_extend_index_yaml(
-        self, index_yaml, web_inf_index_yaml, expected_index_yaml
-    ):
+        self, index_yaml: str, web_inf_index_yaml: str, expected_index_yaml: str
+    ) -> None:
         """Run tests for extend_index_yaml script."""
         with self.index_yaml_swap, self.web_inf_index_yaml_swap:
             with self.open_index_yaml_w as f:
@@ -66,7 +66,7 @@ def tearDown(self) -> None:
         self.index_yaml_file.close()
         self.web_inf_index_yaml_file.close()
 
-    def test_extend_index_yaml_with_changes(self):
+    def test_extend_index_yaml_with_changes(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -111,7 +111,7 @@ def test_extend_index_yaml_with_changes(self):
         self._run_test_for_extend_index_yaml(
             index_yaml, web_inf_index_yaml, expected_index_yaml)
 
-    def test_extend_index_yaml_without_changes(self):
+    def test_extend_index_yaml_without_changes(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -139,7 +139,7 @@ def test_extend_index_yaml_without_changes(self):
         self._run_test_for_extend_index_yaml(
             index_yaml, web_inf_index_yaml, index_yaml)
 
-    def test_extend_index_yaml_with_empty_web_inf_ind_yaml(self):
+    def test_extend_index_yaml_with_empty_web_inf_ind_yaml(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -161,7 +161,7 @@ def test_extend_index_yaml_with_empty_web_inf_ind_yaml(self):
         self._run_test_for_extend_index_yaml(
             index_yaml, web_inf_index_yaml, index_yaml)
 
-    def test_extend_index_yaml_with_same_kind(self):
+    def test_extend_index_yaml_with_same_kind(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -218,7 +218,7 @@ def test_extend_index_yaml_with_same_kind(self):
         self._run_test_for_extend_index_yaml(
             index_yaml, web_inf_index_yaml, expected_index_yaml)
 
-    def test_extend_index_yaml_with_same_kind_in_web_inf(self):
+    def test_extend_index_yaml_with_same_kind_in_web_inf(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -276,7 +276,7 @@ def test_extend_index_yaml_with_same_kind_in_web_inf(self):
         self._run_test_for_extend_index_yaml(
             index_yaml, web_inf_index_yaml, expected_index_yaml)
 
-    def test_extend_index_yaml_with_same_kind_different_order(self):
+    def test_extend_index_yaml_with_same_kind_different_order(self) -> None:
         index_yaml = """indexes:
 
 - kind: AppFeedbackReportModel
@@ -288,7 +288,7 @@ def test_extend_index_yaml_with_same_kind_different_order(self):
   properties:
   - name: blog_post_is_published
   - name: editor_ids
-  - name: story__ids
+  - name: story_ids
   - name: last_updated
     direction: desc
 """
@@ -324,6 +324,14 @@ def test_extend_index_yaml_with_same_kind_different_order(self):
   properties:
   - name: blog_post_is_published
   - name: editor_ids
+  - name: story_ids
+  - name: last_updated
+    direction: desc
+
+- kind: BlogPostRightsModel
+  properties:
+  - name: editor_ids
+  - name: blog_post_is_published
   - name: story__ids
   - name: last_updated
     direction: desc