Code

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#13823 closed Bug (worksforme)

Regression from 1.2.1: admin.site.root_path is None and it breaks admin links

Reported by: gruszczy Owned by: jacmkno
Component: contrib.admin Version: master
Severity: Normal Keywords: root_path admin broken links
Cc: jammon Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX:

Description

Since admin.site.root_path is None, this value is rendered as 'None' rather than empty string in admin links. This is why I have:

https://example.com/admin/Nonelogout/

which is a broken link. There is an easy workaround, that I do in urls.py:

admin.site.root_path = ''

Attachments (1)

root_path.diff (625 bytes) - added by jacmkno 4 years ago.
Changed the root of the diff to django's default

Download all attachments as: .zip

Change History (13)

comment:1 Changed 4 years ago by jacmkno

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jacmkno
  • Patch needs improvement unset
  • Summary changed from admin.site.root_path is None and it is breaks admin links to Regression from 1.2.1: admin.site.root_path is None and it is breaks admin links
  • Triage Stage changed from Unreviewed to Accepted

I confirmed the problem. It has something to do with the deprecation of the root function contrib/admin/sites.py.

comment:2 Changed 4 years ago by jacmkno

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Accepted to Ready for checkin

It seems the problem is that the root_path attribute was not being assigned anywhere but in the constructor with a value of None. I changed the attribute to a property that returns reverse('admin:index') which is the expected value, so there is no need to assign the attribute anymore.

comment:3 Changed 4 years ago by jacmkno

  • Version changed from 1.2 to SVN

comment:4 Changed 4 years ago by jacmkno

  • Summary changed from Regression from 1.2.1: admin.site.root_path is None and it is breaks admin links to Regression from 1.2.1: admin.site.root_path is None and it breaks admin links

comment:5 Changed 4 years ago by jacmkno

  • Status changed from new to assigned

comment:6 Changed 4 years ago by jacmkno

  • Component changed from Uncategorized to django.contrib.admin
  • Keywords root_path admin broken links added

comment:7 Changed 4 years ago by ramiro

  • Triage Stage changed from Ready for checkin to Accepted

I cant' reproduce the initial issue reported here, and I suspect it isn't very common, otherwise we'd have dozens of report similar to this one already.

I'm not saying the proposed workround/fix isn't necessary but IMHO it would be interesting to know what kind of setup leads to this issue. Can you create a reduced version of you admin config (urls.py url map entry and autodiscovery setup, admin model registration, ...) that still shows the problem?

Also, are you migrating you project from pre 1.2-to 1.2 or is it a new, pristine project started with startproject/startapp?

Changed 4 years ago by jacmkno

Changed the root of the diff to django's default

comment:8 Changed 4 years ago by jacmkno

hummm ramiro, seems to be right, I tested this in a brand-new install and... there is no problem.... weird... I'll test a bit further...

comment:9 Changed 4 years ago by jacmkno

  • Resolution set to worksforme
  • Status changed from assigned to closed

weird, there is no problem at all... Sorry about that....

comment:10 follow-up: Changed 3 years ago by jammon

  • Cc jammon added
  • Easy pickings unset
  • Resolution worksforme deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to Bug

As I stumbled into this problem as well, I tried to create a minimal version of a django app reproducing the error. The error for me was, that the "add-another"-link for a ForeignKeyField in the admin site was broken because my_admin_site.root_path was None. (The logout link was ok for me; tested with Django 1.3 and Python 2.7.)

And I came up with this:

myapp/models.py:

from django.db import models

class ClassA(models.Model):
    name = models.CharField(max_length=200)

class ClassB(models.Model):
    refA = models.ForeignKey(ClassA)

myapp/admin.py:

from models import ClassA, ClassB
from django.contrib import admin

datainputsite = admin.sites.AdminSite()

datainputsite.register(ClassA)
datainputsite.register(ClassB)

urls.py:

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

from myapp import admin as dataadmin

urlpatterns = patterns('',
    # If you exchange the sequence of the next two lines, the error disappears.
    (r'^admin/', include(admin.site.urls)),
    (r'^datainput/', include(dataadmin.datainputsite.urls)),
)

and the expected changes in settings.INSTALLED_APPS and settings.DATABASES.

Now when you call /datainput/myapp/classb/add/, the "add-another"-link for RefA is Nonemyapp/classa/add/ because datainputsite.root_path is None. If you change the sequence of the url definitions, the error disappears.

Unfortunately I'm not proficient enough to find a patch for that error. But maybe this way others can reproduce and fix it.

comment:11 in reply to: ↑ 10 ; follow-up: Changed 3 years ago by ramiro

  • Resolution set to worksforme
  • Status changed from reopened to closed

Replying to jammon:

myapp/admin.py:

datainputsite = admin.sites.AdminSite()

urls.py:

urlpatterns = patterns('',
    # If you exchange the sequence of the next two lines, the error disappears.
    (r'^admin/', include(admin.site.urls)),
    (r'^datainput/', include(dataadmin.datainputsite.urls)),

Thanks for providing a minimal test case.

You need to provide an unique identifier for you custom myapp.admin.datainputsite AdminSite instance if you are going to use more than one of them:

http://docs.djangoproject.com/en/1.3/ref/contrib/admin/#adminsite-objects

(you seem to be using it alongside the canonical django.contrib.admin.site instance and both of them are getting the 'admin' default name)

I'm closing the ticket again, pleae feel free to reopen it if fixing that doesn't solve your issue.

comment:12 in reply to: ↑ 11 Changed 3 years ago by jammon

Replying to ramiro:

I'm closing the ticket again, pleae feel free to reopen it if fixing that doesn't solve your issue.

Thank you, that solves it indeed.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.