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 Admin Search on Dissemination Tables #4458

Open
2 tasks done
jperson1 opened this issue Nov 14, 2024 · 1 comment
Open
2 tasks done

Fix Admin Search on Dissemination Tables #4458

jperson1 opened this issue Nov 14, 2024 · 1 comment
Assignees

Comments

@jperson1
Copy link
Contributor

jperson1 commented Nov 14, 2024

In the admin panel, making a search on any dissemination table that isn't "Generals" will result in a crash. This is because report_id is a foreign key, and is not supported by Django's most basic search option. We want this to work properly for searches on common identifying fields such as report_id, UEI, and auditee name.

Stack trace:

Traceback (most recent call last):
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/newrelic/hooks/framework_django.py", line 527, in wrapper
    return wrapped(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/options.py", line 718, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/sites.py", line 241, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/options.py", line 2001, in changelist_view
    cl = self.get_changelist_instance(request)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/options.py", line 866, in get_changelist_instance
    return ChangeList(
           ^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/views/main.py", line 145, in __init__
    self.queryset = self.get_queryset(request)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/views/main.py", line 583, in get_queryset
    qs, search_may_have_duplicates = self.model_admin.get_search_results(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/contrib/admin/options.py", line 1222, in get_search_results
    queryset = queryset.filter(models.Q.create(term_queries))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/query.py", line 1476, in filter
    return self._filter_or_exclude(False, args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/query.py", line 1494, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, args, kwargs)
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/query.py", line 1501, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1609, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1641, in _add_q
    child_clause, needed_inner = self.build_filter(
                                 ^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1468, in build_filter
    return self._add_q(
           ^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1641, in _add_q
    child_clause, needed_inner = self.build_filter(
                                 ^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1468, in build_filter
    return self._add_q(
           ^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1641, in _add_q
    child_clause, needed_inner = self.build_filter(
                                 ^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1555, in build_filter
    condition = self.build_lookup(lookups, col, value)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1379, in build_lookup
    lhs = self.try_transform(lhs, lookup_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vcap/deps/1/python/lib/python3.12/site-packages/django/db/models/sql/query.py", line 1423, in try_transform
    raise FieldError(
django.core.exceptions.FieldError: Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted.

Tasks

Tasks

@github-project-automation github-project-automation bot moved this to Triage in FAC Nov 14, 2024
@rnovak338 rnovak338 self-assigned this Nov 21, 2024
@rnovak338
Copy link
Contributor

@jperson1 I can tackle this in light of separating the new Admin Panel changes from the API architecture.

@rnovak338 rnovak338 moved this from Triage to In Progress in FAC Nov 25, 2024
rnovak338 added a commit that referenced this issue Nov 26, 2024
- Fixed 500 errors from occurring when searching the dissemination tables.
- Extended searchable fields when searching tables in the dissemination section.
@rnovak338 rnovak338 moved this from In Progress to Done in FAC Dec 2, 2024
github-merge-queue bot pushed a commit that referenced this issue Dec 2, 2024
* Initial Commit

- Migrated logic pertaining to all Django Admin changes from API PR.

* Linting

* Adjust staffusers.json based on helpdesk users

* Update staffusers.json

* Feedback v1

- Removed [email protected] from staffusers.
- Removed requirement for user to exist when adding a new `userpermission`.

* Address #4458

- Fixed 500 errors from occurring when searching the dissemination tables.
- Extended searchable fields when searching tables in the dissemination section.

* Support for django admin logs

- Lowercasing emails that are added to TribalApiAccessKeyIds.
- Creating logs for CRUD operations through the Django Admin Panel, using the factory `LogEntry` model.
- New signal for listening to new `LogEntry` records, then modifying its contents for more readable output.

* Linting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants