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

Exception on invalid environment #10207

Open
1 of 3 tasks
kiblik opened this issue May 14, 2024 · 1 comment
Open
1 of 3 tasks

Exception on invalid environment #10207

kiblik opened this issue May 14, 2024 · 1 comment
Labels

Comments

@kiblik
Copy link
Contributor

kiblik commented May 14, 2024

Be informative
DD raises an exception (HTTP-500 - internal server error) if a user uses a name of an non-existing environment in (re)imports

Bug description

ImportScanSerializer.set_context and ReImportScanSerializer.set_context uses

        context["environment"] = Development_Environment.objects.get(
            name=data.get("environment", "Development")
        )

which is able to handle not defined environment but does not handle non-existenting one

Steps to reproduce

curl -X 'POST' \
  'http://xxx:8080/api/v2/reimport-scan/' \
...
  -F 'environment=non_existing_enviro' \
...

Expected behavior
There are 2 options

  • HTTP-400 validation error
  • Create environment - but set_context is happening outside of AutoCreate context

Deployment method (select with an X)

  • Docker Compose
  • Kubernetes
  • GoDojo

Environment information

Logs

uwsgi-1         | [14/May/2024 19:26:39] ERROR [dojo.api_v2.exception_handler:43] Development_Environment matching query does not exist.
uwsgi-1         | Traceback (most recent call last):
uwsgi-1         |   File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
uwsgi-1         |     response = handler(request, *args, **kwargs)
uwsgi-1         |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uwsgi-1         |   File "/usr/local/lib/python3.11/site-packages/rest_framework/mixins.py", line 19, in create
uwsgi-1         |     self.perform_create(serializer)
uwsgi-1         |   File "/app/dojo/api_v2/views.py", line 2792, in perform_create
uwsgi-1         |     serializer.save(push_to_jira=push_to_jira)
uwsgi-1         |   File "/app/dojo/api_v2/serializers.py", line 2538, in save
uwsgi-1         |     context = self.set_context(data)
uwsgi-1         |               ^^^^^^^^^^^^^^^^^^^^^^
uwsgi-1         |   File "/app/dojo/api_v2/serializers.py", line 2415, in set_context
uwsgi-1         |     context["environment"] = Development_Environment.objects.get(
uwsgi-1         |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uwsgi-1         |   File "/usr/local/lib/python3.11/site-packages/django/db/models/manager.py", line 85, in manager_method
uwsgi-1         |     return getattr(self.get_queryset(), name)(*args, **kwargs)
uwsgi-1         |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
uwsgi-1         |   File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 650, in get
uwsgi-1         |     raise self.model.DoesNotExist(
uwsgi-1         | dojo.models.Development_Environment.DoesNotExist: Development_Environment matching query does not exist.
uwsgi-1         | [14/May/2024 19:26:39] ERROR [django.request:241] Internal Server Error: /api/v2/reimport-scan/
@kiblik kiblik added the bug label May 14, 2024
@nelsonleblanc-rl
Copy link

nelsonleblanc-rl commented May 17, 2024

im actually seeing this error on import with undefined environment in 2.33.7

edit: looks like this dd instance did not get the default environments created, somehow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants