Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#13823 closed Bug (worksforme)

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

Reported by: Filip Gruszczyński Owned by: jacmkno
Component: contrib.admin Version: dev
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: no

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 14 years ago.
Changed the root of the diff to django's default

Download all attachments as: .zip

Change History (13)

comment:1 by jacmkno, 14 years ago

Owner: changed from nobody to jacmkno
Summary: admin.site.root_path is None and it is breaks admin linksRegression from 1.2.1: admin.site.root_path is None and it is breaks admin links
Triage Stage: UnreviewedAccepted

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

comment:2 by jacmkno, 14 years ago

Has patch: set
Needs tests: set
Triage Stage: AcceptedReady 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 by jacmkno, 14 years ago

Version: 1.2SVN

comment:4 by jacmkno, 14 years ago

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

comment:5 by jacmkno, 14 years ago

Status: newassigned

comment:6 by jacmkno, 14 years ago

Component: Uncategorizeddjango.contrib.admin
Keywords: root_path admin broken links added

comment:7 by Ramiro Morales, 14 years ago

Triage Stage: Ready for checkinAccepted

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?

by jacmkno, 14 years ago

Attachment: root_path.diff added

Changed the root of the diff to django's default

comment:8 by jacmkno, 14 years ago

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 by jacmkno, 14 years ago

Resolution: worksforme
Status: assignedclosed

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

comment:10 by jammon, 14 years ago

Cc: jammon added
Easy pickings: unset
Resolution: worksforme
Severity: Normal
Status: closedreopened
Type: 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.

in reply to:  10 ; comment:11 by Ramiro Morales, 14 years ago

Resolution: worksforme
Status: reopenedclosed

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.

in reply to:  11 comment:12 by jammon, 14 years ago

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.

Note: See TracTickets for help on using tickets.
Back to Top