Instances "Image Name" filter fails if image without a name exist

Bug #2002027 reported by Stanislav Dmitriev
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
Low
Stanislav Dmitriev

Bug Description

Horizon breaks if "Instances page" "Image Name" filter is invoked and there is an image without name exists.

How to reproduce:

1. Create an image without a name
image list --project 66ae0f36c4184e37b159ef3e9f39ea56 -c Name | more
+-------------------------------------------+
| Name |
+-------------------------------------------+
| None |
| bionic-server |
+-------------------------------------------+

2. Go to Instances tab
3. Put random value to "Image Name" field and press Filter

Error trace:

[Thu Jan 05 19:07:29.668641 2023] [:error] [pid 31] Traceback (most recent call last):
[Thu Jan 05 19:07:29.668647 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
[Thu Jan 05 19:07:29.668651 2023] [:error] [pid 31] response = get_response(request)
[Thu Jan 05 19:07:29.668656 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
[Thu Jan 05 19:07:29.668664 2023] [:error] [pid 31] response = self.process_exception_by_middleware(e, request)
[Thu Jan 05 19:07:29.668669 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
[Thu Jan 05 19:07:29.668695 2023] [:error] [pid 31] response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Thu Jan 05 19:07:29.668699 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/decorators.py", line 52, in dec
[Thu Jan 05 19:07:29.668705 2023] [:error] [pid 31] return view_func(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668708 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/decorators.py", line 36, in dec
[Thu Jan 05 19:07:29.668722 2023] [:error] [pid 31] return view_func(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668725 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/decorators.py", line 36, in dec
[Thu Jan 05 19:07:29.668735 2023] [:error] [pid 31] return view_func(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668749 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/decorators.py", line 113, in dec
[Thu Jan 05 19:07:29.668758 2023] [:error] [pid 31] return view_func(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668762 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/decorators.py", line 84, in dec
[Thu Jan 05 19:07:29.668765 2023] [:error] [pid 31] return view_func(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668775 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
[Thu Jan 05 19:07:29.668778 2023] [:error] [pid 31] return self.dispatch(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668785 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
[Thu Jan 05 19:07:29.668795 2023] [:error] [pid 31] return handler(request, *args, **kwargs)
[Thu Jan 05 19:07:29.668799 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/tables/views.py", line 223, in get
[Thu Jan 05 19:07:29.668802 2023] [:error] [pid 31] handled = self.construct_tables()
[Thu Jan 05 19:07:29.668806 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/tables/views.py", line 214, in construct_tables
[Thu Jan 05 19:07:29.668817 2023] [:error] [pid 31] handled = self.handle_table(table)
[Thu Jan 05 19:07:29.668826 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/tables/views.py", line 123, in handle_table
[Thu Jan 05 19:07:29.668830 2023] [:error] [pid 31] data = self._get_data_dict()
[Thu Jan 05 19:07:29.668836 2023] [:error] [pid 31] File "/usr/lib/python2.7/site-packages/horizon/tables/views.py", line 252, in _get_data_dict
[Thu Jan 05 19:07:29.668844 2023] [:error] [pid 31] self._data = {self.table_class._meta.name: self.get_data()}
[Thu Jan 05 19:07:29.668848 2023] [:error] [pid 31] File "/usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/instances/views.py", line 163, in get_data
[Thu Jan 05 19:07:29.668854 2023] [:error] [pid 31] if not process_non_api_filters(search_opts, non_api_filter_info):
[Thu Jan 05 19:07:29.668863 2023] [:error] [pid 31] File "/usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/instances/views.py", line 245, in process_non_api_filters
[Thu Jan 05 19:07:29.668867 2023] [:error] [pid 31] if not _swap_filter(resources, search_opts, fake_field, real_field):
[Thu Jan 05 19:07:29.668872 2023] [:error] [pid 31] File "/usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/instances/views.py", line 255, in _swap_filter
[Thu Jan 05 19:07:29.668886 2023] [:error] [pid 31] if resource.name.lower() == filter_string.lower()]
[Thu Jan 05 19:07:29.668896 2023] [:error] [pid 31] AttributeError: 'NoneType' object has no attribute 'lower'

Revision history for this message
Stanislav Dmitriev (sdmitriev1) wrote :

Obviously problem occurs in this condition:
https://github.com/openstack/horizon/blob/master/openstack_dashboard/dashboards/project/instances/views.py#L256

matched = [resource for resource in resources
           if resource.name.lower() == filter_string.lower()]

where lower() method is invoked for None (image without a name)

Looks pretty much similar to https://bugs.launchpad.net/horizon/+bug/1581667
I guess the solution might be the same

Changed in horizon:
assignee: nobody → Stanislav Dmitriev (sdmitriev1)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/openstack/horizon/+/869400

Revision history for this message
Vishal Manchanda (vishalmanchanda) wrote :

I tried to reproduce this bug on the master branch and did not succeed.
Could you add more details about where you hit this bug?
Also, I noticed that 'Image Name' filter never works in my env. Is it working for you?

Revision history for this message
Stanislav Dmitriev (sdmitriev1) wrote :

When you tried to reproduce it did you make sure that the image name is actually None and not just an empty string? I don't think that one can create an image without a name using CLI, either using API/SDK or manually set the image name in DB to NULL.
Regarding the filter itself, it works only for the full name, but not for the substring (so if you have instances created from "ubuntu-20.04" image, you will be able to filter them out but using "ubuntu-20.04", just "ubuntu" won't work

Revision history for this message
Akihiro Motoki (amotoki) wrote :

I confirmed the issue when at least one image with name None (JSON null) exists.

Note that "Image Name" filter in the instance table does not pick up servers with boot-from-volume.
Image names are shown for servers with boot-from-volume in the instance table, but they are not shown if "Image Name" filter is applied. I wonder this is the reason Vishal said the image name filter does not work completely.

Revision history for this message
Akihiro Motoki (amotoki) wrote :

The following is what I did to reproduce the bug (using devstack).

- 1. Create a server "s1" using cirros-0.5.2-x86_64-disk image (without using boot-from-volume)
- 2. Create an image snapshot "snap1" for the server s1
- 3. Create a server "s2" using the image snapshot "snap1" (without using boot-from-volume)
- 4. Use "Image Name" filter with a value "cirros-0.5.2-x86_64-disk".
     It works as expected and only server "s1" is shown
- 5. Set the name of "snap1" image to None (JSON null) using curl
- 6. Use "Image Name" filter with a value "cirros-0.5.2-x86_64-disk" again.
     The image name filter fails (as reported in the bug)

Curl command-line of step 5:
curl -H "Content-Type: application/openstack-images-v2.1-json-patch" -X PATCH -d '[{"op": "replace", "path": "/name", "value": null}]' -H "X-Auth-Token: $TOKEN" http://192.168.122.232/image/v2/images/<ID>

Akihiro Motoki (amotoki)
Changed in horizon:
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.opendev.org/c/openstack/horizon/+/869400
Committed: https://opendev.org/openstack/horizon/commit/827d453d7a2e7301da3cabbc34307a765ef3726d
Submitter: "Zuul (22348)"
Branch: master

commit 827d453d7a2e7301da3cabbc34307a765ef3726d
Author: Stanislav Dmitriev <email address hidden>
Date: Thu Jan 5 15:28:46 2023 -0500

    Fix Image Filter for images with None names

    Replacing None with empty string to fix non_api_filters
    processing if resources have None attributes

    Closes-Bug: #2002027
    Change-Id: I57493837cede7747bbb634959ace28b2feffb543

Changed in horizon:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/horizon 23.1.0

This issue was fixed in the openstack/horizon 23.1.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.