[Horizon] Unable to switch Project

Bug #1968858 reported by Ammad Ali
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Incomplete
Undecided
Unassigned
Ubuntu Cloud Archive
Fix Released
Undecided
Unassigned

Bug Description

Hi,

I am using horizon 22.1.0 on ubuntu 20.04 installed from UCA repo. I am unable to switch project from horizon. Getting below error in logs.

[Wed Apr 13 14:02:43.833149 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] INFO openstack_auth.views Project switch successful for user "admin".
[Wed Apr 13 14:02:43.834356 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] ERROR django.request Internal Server Error: /horizon/auth/switch/98687873a146418eaeeb54a01693669f/
[Wed Apr 13 14:02:43.834371 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] Traceback (most recent call last):
[Wed Apr 13 14:02:43.834374 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 34, in inner
[Wed Apr 13 14:02:43.834377 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] response = get_response(request)
[Wed Apr 13 14:02:43.834379 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 115, in _get_response
[Wed Apr 13 14:02:43.834382 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] response = self.process_exception_by_middleware(e, request)
[Wed Apr 13 14:02:43.834384 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 113, in _get_response
[Wed Apr 13 14:02:43.834387 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Wed Apr 13 14:02:43.834405 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] File "/usr/lib/python3/dist-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
[Wed Apr 13 14:02:43.834408 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] return view_func(request, *args, **kwargs)
[Wed Apr 13 14:02:43.834410 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] File "/usr/lib/python3/dist-packages/openstack_auth/views.py", line 295, in switch
[Wed Apr 13 14:02:43.834412 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] if (not http.url_has_allowed_host_and_scheme(
[Wed Apr 13 14:02:43.834414 2022] [wsgi:error] [pid 1126664:tid 140258759444224] [remote 172.16.40.100:61405] AttributeError: module 'django.utils.http' has no attribute 'url_has_allowed_host_and_scheme'

Revision history for this message
Dr. Clemens Hardewig (bringha1) wrote :

Can confirm this issue too, cannot change between projects, only project admin is accepted

Revision history for this message
Andrea Mazzucchi (man-drappa) wrote :

yep, same here.
we're looking into it to figure out exactly where the problem is.

Revision history for this message
Andrea Mazzucchi (man-drappa) wrote :

...so, for the time being, I've commented out lines 295-298 on

usr/lib/python3/dist-packages/openstack_auth/views.py

The code is copied below for quick reference:

    #if (not http.url_has_allowed_host_and_scheme(
    # url=redirect_to,
    # allowed_hosts=[request.get_host()])):
    # redirect_to = settings.LOGIN_REDIRECT_URL

The problem appears to be in a change on url_has_allowed_host_and_scheme in the most recent versions of django. I would NOT recommend this solution on a production environment however it works on our testing environment and I am posting this hoping to help developers to quickly fix the issue.

A.

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

What is the Django version you use?

Horizon yoga (at least as of 22.1.0) support only Django 3.2 (which is the only LTS version of Django right now).
Django 3.2 (+ Django 3.x, 4.0 non-LTS versions) contains django.utils.http.url_has_allowed_host_and_scheme.
The code you commented out should work with Django >=3.0.

If the issue is due to Django 2.2, it would be an issue of the UCA packaging.

Akihiro Motoki (amotoki)
Changed in horizon:
status: New → Incomplete
Revision history for this message
Akihiro Motoki (amotoki) wrote :

IMHO, as upstream, if not small number of deployments would like to use horizon with Django 2.2, we can consider reverting some patches which prepared for Django 4.x in stable/yoga. (I am not saying the upsream stable/yoga will be tested with Django 2.2 though.)

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

I added "Ubuntu Cloud Archive" as an affected project.
python3-django in Ubuntu 20.04 (focal) is Django 2.2 series and it is not compatible with horizon yoga (which requires Django>=3.2,<3.3).
We need to discuss what is a better workaround.

Revision history for this message
Dr. Clemens Hardewig (bringha1) wrote (last edit ):

And what prevents to fix it with a manual installation of Django 3.2 with

pip3 install django --user django

as even the ubuntu wiki recommends if you want to have a newer version of django? or are there further customisation and configs required to make it work with horizon?

Indeed only until UCA has been updated .....

Revision history for this message
Andrea Mazzucchi (man-drappa) wrote :

I tried to install a more recent version of Django, before commenting out those lines.
It messed up with other parts on horizon, breaking completely the service. I didn't investigate any further

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Thank you for reporting this.

python-django 2:3.2.12-2ubuntu1~cloud0 has been backported to the yoga cloud archive and will publish in the next few hours. Please let us know if there are any more issues.

Changed in cloud-archive:
status: New → Fix Released
Revision history for this message
Ammad Ali (syedammad83) wrote :

Hi

I am trying test it and installing openstack-dashboard on fresh ubuntu 20.04 from UCA yoga. But its still failing because of dependencies.

# apt -y install openstack-dashboard python3-django-horizon python3-django-openstack-auth python3-django-pyscss
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3-django-horizon : Depends: python3-django (>= 3.2) but it is not going to be installed
                          Depends: python3-django-compressor (>= 2.4) but it is not going to be installed
                          Depends: python3-django-debreach (>= 1.4.2) but it is not going to be installed
 python3-django-openstack-auth : Depends: python3-django (>= 3.2) but it is not going to be installed
                                 Depends: python3-django-compressor (>= 2.4) but it is not going to be installed
                                 Depends: python3-django-debreach (>= 1.4.2) but it is not going to be installed
 python3-django-pyscss : Depends: python3-django but it is not going to be installed
                         Depends: python3-django-compressor but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I already have required packages installed but apt is still failing dependencies.

# dpkg -l | grep python3-django
ii python3-django 2:3.2.12-2ubuntu1~cloud0 all High-level Python web development framework
ii python3-django-appconf 1.0.3-1 all helper class handling configuration defaults of apps - Python 3.x
ii python3-django-compressor 2.4-2ubuntu1~cloud0 all Compresses linked, inline JS or CSS into single cached files - Python 3.x
ii python3-django-debreach 2.0.1-0ubuntu1 all Protection against the BREACH attack in Django - Python 3

Revision history for this message
Dr. Clemens Hardewig (bringha1) wrote (last edit ):

I run also still into issues:

apt install python3-manila-ui openstack-dashboard python3-django-horizon python3-django-openstack-auth python3-django-pyscss python3-django python3-django-compressor python3-django-debreach
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3-django : Breaks: python3-django-pyscss (< 2.0.2-10~) but 2.0.2-9 is to be installed

seems to be that still a package update is missing

Revision history for this message
Corey Bryant (corey.bryant) wrote :

Apologies, that introduced a new error that I'm working on and tracking via this bug: https://bugs.launchpad.net/charm-openstack-dashboard/+bug/1969631

Revision history for this message
Dr. Clemens Hardewig (bringha1) wrote (last edit ):

With the recent UCA update with working packages for python-django (3.2) and python-django-pyscss (2.0.2-10~)the bug is fixed for me. Change of projects now works. The workaround from above is now obsolete.

As a side effect the openstack-dashboard feels much more agile and faster ...

Thanks to Corey for the fast reaction and fix

@Akihiro: I think, there is no need to continue with django 2.2 support resp rollback any preparation work for django 4.x prep work. As for Ubuntu jammy django 3.2 will be standard anyway, ...

Revision history for this message
DJENNANE Zoheir (djdreamerdz79) wrote :

it's mismatch Django version :
Just replace if (not http.url_has_allowed_host_and_scheme(.. by if (not http.is_safe_url(..
in usr/lib/python3/dist-packages/openstack_auth/views.py

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.