Skip to content

Add PACKAGE_TYPES choices to PackageString model#839

Open
mdhowle wants to merge 1 commit into
furlongm:mainfrom
mdhowle:fix-pkgstring-pkgtype-display
Open

Add PACKAGE_TYPES choices to PackageString model#839
mdhowle wants to merge 1 commit into
furlongm:mainfrom
mdhowle:fix-pkgstring-pkgtype-display

Conversation

@mdhowle

@mdhowle mdhowle commented Jun 8, 2026

Copy link
Copy Markdown

This fixes the AttributeError: 'PackageString' object has no attribute 'get_packagetype_display' exception.

By adding the choices kwarg for PackageString.packagetype, the get_packagetype_display() method is added to the PackageString model object.

@mdhowle mdhowle changed the title Add PACKAGE_TYPES choices Add PACKAGE_TYPES choices to PackageString model Jun 8, 2026
@furlongm

Copy link
Copy Markdown
Owner

Do you have the stacktrace where you come across this exception?

@mdhowle

mdhowle commented Jun 12, 2026

Copy link
Copy Markdown
Author

Sure, it was during a patchman -r:

Extracting 64564 Packages          : 100%|==========================================================================================================================================================================| 64564/64564 [00:05<00:00, 11148.18it/s]
Fetching 2179 existing Packages    : 100%|============================================================================================================================================================================| 2179/2179 [00:00<00:00, 44635.73it/s]
Adding 62385 new Packages          :   0%|                                                                                                                                                                              | 152/62385 [00:01<08:11, 126.68it/s]Traceback (most recent call last):
  File "/srv/patchman/.venv/lib/python3.13/site-packages/repos/utils.py", line 85, in update_mirror_packages
    package = convert_packagestring_to_package(strpackage)
  File "/srv/patchman/.venv/lib/python3.13/site-packages/packages/utils.py", line 68, in convert_packagestring_to_package
    package, created = Package.objects.get_or_create(
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
          name=name,
          ^^^^^^^^^^
    ...<5 lines>...
          category=category,
          ^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 918, in get_or_create
    return self.get(**kwargs), False
           ~~~~~~~~^^^^^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/django/db/models/query.py", line 642, in get
    raise self.model.MultipleObjectsReturned(
    ...<5 lines>...
    )
packages.models.Package.MultipleObjectsReturned: get() returned more than one Package -- it returned 2!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/patchman/.venv/bin/patchman", line 521, in <module>
    main()
    ~~~~^^
  File "/srv/patchman/.venv/bin/patchman", line 515, in main
    showhelp = process_args(args)
  File "/srv/patchman/.venv/bin/patchman", line 471, in process_args
    refresh_repos(args.repo, args.force)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/patchman/.venv/bin/patchman", line 126, in refresh_repos
    repo.refresh(force)
    ~~~~~~~~~~~~^^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/repos/models.py", line 93, in refresh
    refresh_deb_repo(self)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/repos/repo_types/deb.py", line 115, in refresh_deb_repo
    update_mirror_packages(mirror, packages)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/repos/utils.py", line 88, in update_mirror_packages
    error_message(text=f'Duplicate Package found in {mirror}: {strpackage}')
                                                              ^^^^^^^^^^^^
  File "/srv/patchman/.venv/lib/python3.13/site-packages/packages/models.py", line 206, in __str__
    return f'{self.name}_{epo}{self.version}{rel}_{self.arch}.{self.get_packagetype_display()}'
                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PackageString' object has no attribute 'get_packagetype_display'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants