openedx / openedx-learning

GNU Affero General Public License v3.0
5 stars 11 forks source link

Fix minor asset storage admin issue [FC-0062] #247

Closed pomegranited closed 4 weeks ago

pomegranited commented 4 weeks ago

Admin page calls contents.os_path(), and if the storage backend doesn't support path, we can't load the admin page for that asset.

See e.g https://tagging-preview.staging.do.opencraft.hosting/admin/oel_contents/content/225/change/

Traceback: ``` 2024-10-24 05:36:25,936 ERROR 15 [django.request] [user 20] [ip 180.150.117.27] log.py:241 - Internal Server Error: /admin/oel_contents/content/225/change/ Traceback (most recent call last): File "/openedx/venv/lib/python3.11/site-packages/django/db/models/options.py", line 681, in get_field return self.fields_map[field_name] ~~~~~~~~~~~~~~~^^^^^^^^^^^^ KeyError: 'os_path' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 272, in lookup_field f = _get_non_gfk_field(opts, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 303, in _get_non_gfk_field field = opts.get_field(name) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/db/models/options.py", line 683, in get_field raise FieldDoesNotExist( django.core.exceptions.FieldDoesNotExist: Content has no field named 'os_path' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 220, in _get_response response = response.render() ^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/response.py", line 114, in render self.content = self.rendered_content ^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/response.py", line 92, in rendered_content return template.render(context, self._request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 175, in render return self._render(context) ^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/loader_tags.py", line 157, in render return compiled_parent._render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/loader_tags.py", line 63, in render result = block.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/loader_tags.py", line 63, in render result = block.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/loader_tags.py", line 208, in render return template.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 177, in render return self._render(context) ^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 167, in _render return self.nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/defaulttags.py", line 238, in render nodelist.append(node.render_annotated(context)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/defaulttags.py", line 321, in render return nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/defaulttags.py", line 321, in render return nodelist.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in render return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1005, in return SafeString("".join([node.render_annotated(context) for node in self])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 966, in render_annotated return self.render(context) ^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 1064, in render output = self.filter_expression.resolve(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 715, in resolve obj = self.var.resolve(context) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 847, in resolve value = self._resolve_lookup(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/template/base.py", line 914, in _resolve_lookup current = current() ^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/helpers.py", line 273, in contents f, attr, value = lookup_field(field, obj, model_admin) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/contrib/admin/utils.py", line 281, in lookup_field value = attr(obj) ^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/openedx_learning/apps/authoring/contents/admin.py", line 44, in os_path return content.os_path() or "" ^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/openedx_learning/apps/authoring/contents/models.py", line 320, in os_path return get_storage().path(self.path) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/openedx/venv/lib/python3.11/site-packages/django/core/files/storage/base.py", line 132, in path raise NotImplementedError("This backend doesn't support absolute paths.") NotImplementedError: This backend doesn't support absolute paths. ```

Private-ref: FAL-3908

openedx-webhooks commented 4 weeks ago

Thanks for the pull request, @pomegranited!

What's next?

Please work through the following steps to get your changes ready for engineering review:

:radio_button: Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

:radio_button: Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

:radio_button: Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

:radio_button: Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @axim-engineering. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

:bulb: As a result it may take up to several weeks or months to complete a review and merge your PR.

ormsbee commented 4 weeks ago

Doesn't block merge, but a couple of questions:

  1. Out of curiosity, what storage backend is the sandbox running?
  2. If people are going to be running in this mode commonly, would it make sense to just log a warning and return None?
pomegranited commented 4 weeks ago

@ormsbee

  1. Out of curiosity, what storage backend is the sandbox running?

Sandbox uses s3, and it doesn't have a path, just a URL.

From the docs:

path(name)[source]

The local filesystem path where the file can be opened using Python’s standard open(). For storage systems that aren’t accessible from the local filesystem, this will raise NotImplementedError instead.

  1. If people are going to be running in this mode commonly, would it make sense to just log a warning and return None?

That's what this change does.. Oh, would you rather a log.warning instead of log.exception?

ormsbee commented 4 weeks ago

That's what this change does.. Oh, would you rather a log.warning instead of log.exception?

Yeah, just because log.exception is really loud/long, and if it's a routine thing, it's not really an error of that sort.