Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add improperly configured exception in load permissions function #274

Merged
merged 7 commits into from
Jul 19, 2024

Conversation

BryanttV
Copy link
Contributor

@BryanttV BryanttV commented Jul 18, 2024

Description

This PR adds an ImproperlyConfigured exception in load_permissions function to avoid errors during the build.

Error

Details of error
 => ERROR [production 19/37] RUN ./manage.py lms --settings=tutor.i18n pull_plugin_translations --verbose --repository='openedx/openedx-translations' --revision='o  5.3s
------
 > [production 19/37] RUN ./manage.py lms --settings=tutor.i18n pull_plugin_translations --verbose --repository='openedx/openedx-translations' --revision='open-release/redwood.1':
4.572 Traceback (most recent call last):
4.572   File "/openedx/edx-platform/./manage.py", line 106, in <module>
4.572     execute_from_command_line([sys.argv[0]] + django_args)
4.572   File "/openedx/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
4.572     utility.execute()
4.572   File "/openedx/venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
4.573     self.fetch_command(subcommand).run_from_argv(self.argv)
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
4.573     self.execute(*args, **cmd_options)
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/management/base.py", line 453, in execute
4.573     self.check()
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/management/base.py", line 485, in check
4.573     all_issues = checks.run_checks(
4.573                  ^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
4.573     new_errors = check(app_configs=app_configs, databases=databases)
4.573                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/checks/urls.py", line 42, in check_url_namespaces_unique
4.573     all_namespaces = _load_all_namespaces(resolver)
4.573                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/core/checks/urls.py", line 61, in _load_all_namespaces
4.573     url_patterns = getattr(resolver, "url_patterns", [])
4.573                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
4.573     res = instance.__dict__[self.name] = self.func(instance)
4.573                                          ^^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns
4.573     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
4.573                        ^^^^^^^^^^^^^^^^^^^
4.573   File "/openedx/venv/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
4.574     res = instance.__dict__[self.name] = self.func(instance)
4.574                                          ^^^^^^^^^^^^^^^^^^^
4.574   File "/openedx/venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
4.574     return import_module(self.urlconf_name)
4.574            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.574   File "/opt/pyenv/versions/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
4.574     return _bootstrap._gcd_import(name[level:], package, level)
4.574            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.574   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
4.574   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
4.574   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
4.574   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
4.574   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
4.574   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
4.574   File "/openedx/edx-platform/lms/urls.py", line 998, in <module>
4.575     urlpatterns.extend(get_plugin_url_patterns(ProjectType.LMS))
4.575                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.575   File "/openedx/venv/lib/python3.11/site-packages/edx_django_utils/plugins/plugin_urls.py", line 34, in get_plugin_url_patterns
4.575     return [
4.575            ^
4.575   File "/openedx/venv/lib/python3.11/site-packages/edx_django_utils/plugins/plugin_urls.py", line 35, in <listcomp>
4.575     _get_url(url_module_path, url_config)
4.575   File "/openedx/venv/lib/python3.11/site-packages/edx_django_utils/plugins/plugin_urls.py", line 24, in _get_url
4.575     return re_path(regex, include((url_module_path, app_name), namespace=namespace))
4.575                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.575   File "/openedx/venv/lib/python3.11/site-packages/django/urls/conf.py", line 38, in include
4.575     urlconf_module = import_module(urlconf_module)
4.575                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.575   File "/opt/pyenv/versions/3.11.8/lib/python3.11/importlib/__init__.py", line 126, in import_module
4.575     return _bootstrap._gcd_import(name[level:], package, level)
4.575            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.575   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
4.575   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
4.575   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
4.575   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
4.575   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
4.575   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
4.575   File "/openedx/venv/lib/python3.11/site-packages/eox_core/urls.py", line 6, in <module>
4.576     from eox_core.api_schema import docs_ui_view
4.576   File "/openedx/venv/lib/python3.11/site-packages/eox_core/api_schema.py", line 12, in <module>
4.576     from eox_core.api.v1 import views
4.576   File "/openedx/venv/lib/python3.11/site-packages/eox_core/api/v1/__init__.py", line 8, in <module>
4.576     load_permissions()
4.576   File "/openedx/venv/lib/python3.11/site-packages/eox_core/api/v1/permissions.py", line 20, in load_permissions
4.576     content_type = ContentType.objects.get_for_model(User)
4.576                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.576   File "/openedx/venv/lib/python3.11/site-packages/django/contrib/contenttypes/models.py", line 52, in get_for_model
4.576     ct = self.get(app_label=opts.app_label, model=opts.model_name)
4.576          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.576   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method
4.576     return getattr(self.get_queryset(), name)(*args, **kwargs)
4.576            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.576   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/query.py", line 633, in get
4.576     num = len(clone)
4.576           ^^^^^^^^^^
4.576   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/query.py", line 380, in __len__
4.577     self._fetch_all()
4.577   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/query.py", line 1881, in _fetch_all
4.577     self._result_cache = list(self._iterable_class(self))
4.577                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.577   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/query.py", line 91, in __iter__
4.577     results = compiler.execute_sql(
4.577               ^^^^^^^^^^^^^^^^^^^^^
4.577   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1549, in execute_sql
4.577     sql, params = self.as_sql()
4.578                   ^^^^^^^^^^^^^
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 736, in as_sql
4.578     extra_select, order_by, group_by = self.pre_sql_setup(
4.578                                        ^^^^^^^^^^^^^^^^^^^
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 84, in pre_sql_setup
4.578     self.setup_query(with_col_aliases=with_col_aliases)
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 73, in setup_query
4.578     self.select, self.klass_info, self.annotation_col_map = self.get_select(
4.578                                                             ^^^^^^^^^^^^^^^^
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 296, in get_select
4.578     sql, params = self.compile(col)
4.578                   ^^^^^^^^^^^^^^^^^
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 546, in compile
4.578     sql, params = node.as_sql(self, self.connection)
4.578                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.578   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/expressions.py", line 1141, in as_sql
4.579     sql = ".".join(map(compiler.quote_name_unless_alias, identifiers))
4.579           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.579   File "/openedx/venv/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 537, in quote_name_unless_alias
4.579     r = self.connection.ops.quote_name(name)
4.579         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4.579   File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/dummy/base.py", line 20, in complain
4.579     raise ImproperlyConfigured(
4.579 django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
------
Dockerfile:183
--------------------
 181 |     # Pull latest translations via atlas
 182 |     RUN make clean_translations
 183 | >>> RUN ./manage.py lms --settings=tutor.i18n pull_plugin_translations --verbose --repository='openedx/openedx-translations' --revision='open-release/redwood.1'
 184 |     RUN ./manage.py lms --settings=tutor.i18n pull_xblock_translations --repository='openedx/openedx-translations' --revision='open-release/redwood.1'
 185 |     RUN atlas pull --repository='openedx/openedx-translations' --revision='open-release/redwood.1'  \
--------------------
ERROR: failed to solve: process "/bin/sh -c ./manage.py lms --settings=tutor.i18n pull_plugin_translations --verbose --repository='openedx/openedx-translations' --revision='open-release/redwood.1'" did not complete successfully: exit code: 1
Error: Command failed with status 1: docker buildx build --tag=docker.io/overhangio/openedx:18.1.1-indigo --no-cache --output=type=docker --cache-from=type=registry,ref=docker.io/overhangio/openedx:18.1.1-indigo-cache /home/bryanttv/edunext/tutor/redwood/ednx/env/build/openedx

Testing instructions

  1. Create an environment with Redwood release, you can use Tutor or TVM.

  2. Add in your config.yml this plugin as extra requirement.

    OPENEDX_EXTRA_PIP_REQUIREMENTS:
    - git+https://github.com/eduNEXT/eox-core.git@bav/fix-load-permissions
  3. Run tutor images build openedx --no-cache

  4. Your build should finish smoothly.

@BryanttV BryanttV force-pushed the bav/fix-load-permissions branch from 056afe4 to f040a5f Compare July 18, 2024 16:19
@BryanttV BryanttV marked this pull request as ready for review July 18, 2024 16:37
@BryanttV BryanttV requested a review from a team July 18, 2024 16:38
@BryanttV BryanttV force-pushed the bav/fix-load-permissions branch 2 times, most recently from 7ac729e to ea06157 Compare July 18, 2024 23:06
@MaferMazu
Copy link
Contributor

Thanks for the PR, @BryanttV, it works.

We implemented this fix in eox-tenant, https://github.com/eduNEXT/eox-tenant/pull/178/files, but I wonder if that's the best way.

Well... If we use this solution, I suggest adding more code documentation explaining why we need this.

@BryanttV BryanttV force-pushed the bav/fix-load-permissions branch from ea06157 to c52c906 Compare July 19, 2024 00:44
@BryanttV BryanttV force-pushed the bav/fix-load-permissions branch from 9e6adaa to 8f54684 Compare July 19, 2024 01:11
@BryanttV
Copy link
Contributor Author

Hi @MaferMazu, As the error is raised in the same try-except we can simplify the code and add another exception. It works the same, but it is clearer. I also updated the comment about the reasons for including this code. Let me know if you want any additional modifications, thanks!

@github-actions github-actions bot added size/s and removed size/xs labels Jul 19, 2024
mariajgrimaldi
mariajgrimaldi previously approved these changes Jul 19, 2024
Copy link
Contributor

@magajh magajh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @BryanttV. I agree that catching both exceptions in a single except block is better than what was done in eox-tenant. I just have a suggestion regarding the code comment.

eox_core/api/v1/permissions.py Outdated Show resolved Hide resolved
README.rst Show resolved Hide resolved
magajh
magajh previously approved these changes Jul 19, 2024
@BryanttV BryanttV merged commit a8ae715 into master Jul 19, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants