Nix-Security-WG / nix-security-tracker

Web service for managing information on vulnerabilities in software distributed through Nixpkgs
34 stars 8 forks source link

MultipleObjectsReturned on `manage regenerate_cached_suggestions` #381

Open erictapen opened 6 days ago

erictapen commented 6 days ago

After https://github.com/Nix-Security-WG/nix-security-tracker/pull/378, when running manage regenerate_cached_suggestions, I get this error after a while:

INFO 2024-11-21 09:33:41,227 cache_suggestions 222192 139727664719680 CVE 'CVE-2024-35678' suggestion cached for the first time
INFO 2024-11-21 09:33:41,389 cache_suggestions 222192 139727664719680 CVE 'CVE-2024-35684' suggestion cached for the first time
INFO 2024-11-21 09:33:41,535 cache_suggestions 222192 139727664719680 CVE 'CVE-2024-35695' suggestion cached for the first time
Traceback (most recent call last):
  File "/home/kerstin/git/nix-security-tracker/src/website/manage.py", line 23, in <module>
    main()                                                                                                                             
  File "/home/kerstin/git/nix-security-tracker/src/website/manage.py", line 19, in main
    execute_from_command_line(sys.argv)
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/core/management/__init
__.py", line 442, in execute_from_command_line
    utility.execute()                                              
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/core/management/__init
__.py", line 436, in execute                                       
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/core/management/base.p
y", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/core/management/base.p
y", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kerstin/git/nix-security-tracker/src/website/shared/management/commands/regenerate_cached_suggestions.py", line 21, in ha
ndle
    cache_new_suggestions(suggestion)
  File "/home/kerstin/git/nix-security-tracker/src/website/shared/listeners/cache_suggestions.py", line 83, in cache_new_suggestions
    _, created = CachedSuggestions.objects.update_or_create(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/db/models/manager.py",
 line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/db/models/query.py", l
ine 949, in update_or_create
    obj, created = self.select_for_update().get_or_create(defaults, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/db/models/query.py", l
ine 916, in get_or_create
    return self.get(**kwargs), False
           ^^^^^^^^^^^^^^^^^^
  File "/nix/store/czy8aaqwkypcwnw9ckcz9rj387mhfm6n-python3.12-django-4.2.16/lib/python3.12/site-packages/django/db/models/query.py", l
ine 640, in get
    raise self.model.MultipleObjectsReturned(
shared.models.cached.CachedSuggestions.MultipleObjectsReturned: get() returned more than one CachedSuggestions -- it returned 2!

Any ideas, @RaitoBezarius @fricklerhandwerk ?

erictapen commented 5 days ago

Interestingly this only happens sometimes?