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

Unable to set selector for user model in forms #15102

Closed
abhi1693 opened this issue Feb 9, 2024 · 2 comments · Fixed by #15103
Closed

Unable to set selector for user model in forms #15102

abhi1693 opened this issue Feb 9, 2024 · 2 comments · Fixed by #15103
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@abhi1693
Copy link
Member

abhi1693 commented Feb 9, 2024

Deployment Type

Self-hosted

NetBox Version

v3.7.2

Python Version

3.10

Steps to Reproduce

Inside a NetBoxModelForm, add a field for NetBoxUser with selector=True

class Form(NetBoxModelForm):
assigned_to = DynamicModelMultipleChoiceField(
        queryset=User.objects.all(),
        selector=True,
    )

Expected Behavior

Select search form should open up

Observed Behavior

"GET /htmx/object-selector/?_model=users.netboxuser&target=id_assigned_to HTTP/1.1" 200 5576
Internal Server Error: /htmx/object-selector/
Traceback (most recent call last):
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 16, in cached_import
    return getattr(module, class_name)
AttributeError: module 'users.filtersets' has no attribute 'NetBoxUserFilterSet'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/asaharan/PycharmProjects/netbox/netbox/netbox/views/htmx.py", line 20, in get
    filterset = self._get_filterset_class(model)
  File "/home/asaharan/PycharmProjects/netbox/netbox/netbox/views/htmx.py", line 56, in _get_filterset_class
    return import_string(f'{app_label}.filtersets.{class_name}')
  File "/home/asaharan/PycharmProjects/netbox/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 32, in import_string
    raise ImportError(
ImportError: Module "users.filtersets" does not define a "NetBoxUserFilterSet" attribute/class
"GET /htmx/object-selector/?_model=users.netboxuser&_search=true&q=&is_active=&is_staff=&is_superuser= HTTP/1.1" 500 130748
@abhi1693 abhi1693 added type: bug A confirmed report of unexpected behavior in the application severity: low Does not significantly disrupt application functionality, or a workaround is available labels Feb 9, 2024
@abhi1693 abhi1693 self-assigned this Feb 9, 2024
@abhi1693 abhi1693 added the status: accepted This issue has been accepted for implementation label Feb 9, 2024
@jeffgdotorg
Copy link
Contributor

@abhi1693 are you aware of the custom user model work being done for v4.0 under #12795? Can this issue wait until 4.0 so that we avoid a merge conflict?

@abhi1693
Copy link
Member Author

I'm aware but this is a simple fix and without this my plugins will not work on v3.7.x. Besides it doesn't change the functionality but makes the code consistent and I don't think it should create any conflict as only the class names have been fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants