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

Fix Basename Parsing in Router Registration Method #1123

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

davner
Copy link
Contributor

@davner davner commented Nov 22, 2024

This PR addresses an issue in the register method of the custom SharedAPIRootRouter class, where the basename was not being correctly parsed due to an error in the logical expression’s precedence. This led to the basename being incorrectly set to None. This was discovered due to our tom crashing in cases where viewsets do not have a queryset to fall back on for default basename generation.

With the fix

registering new views: args: ('runprocessor', <class 'goats_tom.views.run_processor.RunProcessorViewSet'>), kwargs: {'basename': 'runprocessor'}

viewset = <class 'goats_tom.views.run_processor.RunProcessorViewSet'>, basename = 'runprocessor'

Without the fix

registering new views: args: ('runprocessor', <class 'goats_tom.views.run_processor.RunProcessorViewSet'>), kwargs: {'basename': 'runprocessor'}
viewset = <class 'goats_tom.views.run_processor.RunProcessorViewSet'>, basename = None

  router.register(r"runprocessor", views.RunProcessorViewSet, basename="runprocessor")

  File "/Users/dan.avner/git-clones/tom_base/tom_common/api_router.py", line 18, in register

    basename = self.shared_router.get_default_basename(viewset)

  File "/Users/dan.avner/miniconda3/envs/goats-env/lib/python3.10/site-packages/rest_framework/routers.py", line 170, in get_default_basename

    assert queryset is not None, '`basename` argument not specified, and could ' \

AssertionError: `basename` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.

@jchate6 jchate6 added the User Issue Raised by a user label Nov 22, 2024
@jchate6 jchate6 self-assigned this Nov 22, 2024
@jchate6 jchate6 removed their assignment Nov 22, 2024
Copy link
Contributor

@jchate6 jchate6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Catch!
Thanks!

@jchate6 jchate6 merged commit 4d4ed4a into TOMToolkit:dev Dec 5, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User Issue Raised by a user
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants