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

500 error occurs when an improperly formatted policies.yml file is uploaded #1560

Closed
JonoYang opened this issue Jan 22, 2025 · 1 comment
Closed
Assignees
Labels
bug Something isn't working web-ui

Comments

@JonoYang
Copy link
Member

When a project is created with a policies.yml file with formatting issues, a 500 error occurs when trying to visit the project page. This is the exception message in the server logs:

web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 320, in render
web-1     |     match = condition.eval(context)
web-1     |             ^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/template/defaulttags.py", line 886, in eval
web-1     |     return self.value.resolve(context, ignore_failures=True)
web-1     |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/template/base.py", line 718, in resolve
web-1     |     obj = self.var.resolve(context)
web-1     |           ^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/template/base.py", line 850, in resolve
web-1     |     value = self._resolve_lookup(context)
web-1     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/template/base.py", line 893, in _resolve_lookup
web-1     |     current = getattr(current, bit)
web-1     |               ^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/scanpipe/models.py", line 1457, in policies_enabled
web-1     |     return bool(self.policy_index)
web-1     |                 ^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/.venv/lib/python3.12/site-packages/django/utils/functional.py", line 47, in __get__
web-1     |     res = instance.__dict__[self.name] = self.func(instance)
web-1     |                                          ^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/scanpipe/models.py", line 1452, in policy_index
web-1     |     return self.get_policy_index()
web-1     |            ^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/scanpipe/models.py", line 1443, in get_policy_index
web-1     |     policies_dict = policies.load_policies_file(policies_file)
web-1     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/scanpipe/policies.py", line 41, in load_policies_file
web-1     |     policies_dict = load_policies_yaml(policies_yaml=policies_file.read_text())
web-1     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |   File "/opt/scancodeio/scanpipe/policies.py", line 33, in load_policies_yaml
web-1     |     raise ValidationError(f"Policies format error: {e}")
web-1     | django.core.exceptions.ValidationError: ['Policies format error: mapping values are not allowed in this context\n  in "<unicode string>", line 53, column 43']

In the case where policies.yml is invalid, we should still be able to see the project page and a message should appear that there is an issue with policies.yml

@JonoYang JonoYang added bug Something isn't working web-ui labels Jan 22, 2025
tdruez added a commit that referenced this issue Jan 23, 2025
@tdruez
Copy link
Contributor

tdruez commented Jan 23, 2025

Fixed in #1561
The page will now load properly with an error message about the improperly formatted policies.yml file.

@tdruez tdruez closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working web-ui
Projects
None yet
Development

No branches or pull requests

2 participants