django-DefectDojo icon indicating copy to clipboard operation
django-DefectDojo copied to clipboard

Issue while importing SonarQube HTML report "MultipleObjectsReturned at /product/4/import_scan_results"

Open MagicScorpion opened this issue 7 years ago • 7 comments

I am trying to import the SonarQube scan report into defectdojo but I am getting below error.

Request Method: POST
https://defectdojo.shure.com/product/4/import_scan_results
2.2.4
MultipleObjectsReturned
get() returned more than one Development_Environment -- it returned 2!
/usr/local/lib/python3.6/site-packages/django/db/models/query.py in get, line 412
/bin/python3
3.6.8
['/usr/local/lib64/python3.6/site-packages/git/ext/gitdb', '/opt/django-DefectDojo', '/opt/django-DefectDojo', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/root/.local/lib/python3.6/site-packages', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages/gitdb/ext/smmap']
Mon, 28 Oct 2019 14:01:24 +0000

Steps to reproduce Steps to reproduce the behavior:

  1. Go to 'Product'
  2. Click on 'Any product or create a new product'
  3. Click on findings
  4. Import Scan results
  5. Select Scan type as SonarQube scan
  6. Click on upload file

Deployment method *

  • [X] setup.bash / legacy-setup.bash

Environment information

  • Operating System: [e.g. CentOS] -- CentOS
  • DefectDojo Commit Message: [use git show -s --format="%h: %s [%ci]"]

Environment:

Request Method: POST Request URL: https://defectdojo.shure.com/product/4/import_scan_results

Django Version: 2.2.4 Python Version: 3.6.8 Installed Applications: ('django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'polymorphic', 'overextends', 'django.contrib.admin', 'django.contrib.humanize', 'gunicorn', 'tastypie', 'auditlog', 'dojo', 'tastypie_swagger', 'watson', 'tagging', 'custom_field', 'imagekit', 'multiselectfield', 'rest_framework', 'rest_framework.authtoken', 'rest_framework_swagger', 'dbbackup', 'taggit_serializer', 'django_celery_results', 'social_django') Installed Middleware: ['django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'dojo.middleware.LoginRequiredMiddleware', 'dojo.middleware.TimezoneMiddleware', 'social_django.middleware.SocialAuthExceptionMiddleware']

Traceback:

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 115. response = self.process_exception_by_middleware(e, request)

File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 113. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 21. return view_func(request, *args, **kwargs)

File "/opt/django-DefectDojo/dojo/product/views.py" in import_scan_results_prod 413. return import_scan_results(request, pid=pid)

File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 21. return view_func(request, *args, **kwargs)

File "/opt/django-DefectDojo/dojo/engagement/views.py" in import_scan_results 495. name="Development")

File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method 82. return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in get_or_create 538. return self.get(**kwargs), False

File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py" in get 412. (self.model._meta.object_name, num)

Exception Type: MultipleObjectsReturned at /product/4/import_scan_results Exception Value: get() returned more than one Development_Environment -- it returned 2!

MagicScorpion avatar Oct 28 '19 14:10 MagicScorpion

Hi @MagicScorpion ; Would you be able to provide an anonymised report that produces the issue? On what version / commit of defectDojo are you running? can you post the result of use git show -s --format="%h: %s [%ci]"

Thanks!

ptrovatelli avatar Nov 02 '19 21:11 ptrovatelli

Hi @MagicScorpion ; Would you be able to provide an anonymised report that produces the issue? On what version / commit of defectDojo are you running? can you post the result of use git show -s --format="%h: %s [%ci]"

Thanks!

git show -s --format="%h: %s [%ci]" 42f1d4e: Update issue templates [2019-10-02 16:01:25 -0500]

please find attached file.

sonar-report-v1.1.0_java-tomcat_Sonarcloud-v8.0.0.485.html.zip

MagicScorpion avatar Nov 04 '19 15:11 MagicScorpion

Hi @MagicScorpion I have tried on a fresh docker install on dev branch and on 42f1d4e : i cannot replicate: it imports fine. Looking at the stack trace, it doesn't look like it's related to the sonar report itself Can you try with another scanner to confirm? (something else than sonar)

I'd say that something is wrong in your database: this "development_environment" object has 2 occurences when it should be one only, which makes the import fail. Maybe the initializer messed up something or ran twice. Has your application ever worked? If not, maybe try a fresh install and see how that works...

ptrovatelli avatar Nov 09 '19 22:11 ptrovatelli

this page gives some insight about that get() returned more than one Development_Environment -- it returned 2! exception

https://stackoverflow.com/questions/22063748/django-get-returned-more-than-one-topic

ptrovatelli avatar Nov 09 '19 22:11 ptrovatelli

@ptrovatelli

Yeah... I was using the setup.bash to install defect dojo as I wanted to use external database. Everything is looking perfect with docker compose install and I am able to import the report.

Can you please tell me docker-compose.yml file changes and other respective changes in order to use our external database which is hosted on the other server?

MagicScorpion avatar Nov 20 '19 16:11 MagicScorpion

@MagicScorpion i haven't tested with an external database. I guess you may need to completely remove the "mysql" sevice from the docker-compose.yml as this is in charge of creating the database and the defectdojo user in it Then you need to properly configure the other services with your database information.

ptrovatelli avatar Dec 18 '19 07:12 ptrovatelli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 17 '20 08:03 stale[bot]