Opened 19 years ago

Closed 19 years ago

#322 closed enhancement (fixed)

[patch] Admin unavailable in development server after [503]

Reported by: jbennett@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Just updated from 494 to 503, and now the admin area is unavailable; going to /admin/ gets the following:

There's been an error:

Traceback (most recent call last):

  File "/var/www/django/django_src/django/core/handlers/base.py", line 62, in get_response
    return callback(request, **param_dict)

  File "/var/www/django/django_src/django/views/admin/main.py", line 50, in index
    c = Context(request, {'title': 'Site administration'})

  File "/var/www/django/django_src/django/core/extensions.py", line 14, in __init__
    self['messages'] = request.user.get_and_delete_messages()

  File "/var/www/django/django_src/django/models/auth.py", line 128, in get_and_delete_messages
    for m in self.get_message_list():

AttributeError: 'User' object has no attribute 'get_message_list'

This is using Python 2.4.1/MySQL 4.0.23.

Change History (10)

comment:1 by garthk@…, 19 years ago

+1

2.4.1, sqlite3

comment:2 by matt@…, 19 years ago

Summary: Admin unavailable after upgrade to revision 503Admin unavailable after upgrade to revision 503 (works in 502)

Revision 502 works, 503 is broken. Corroborated by about three more people...

I'm guessing it's something in the model validation code, given that's about all that changes outside of django-admin.py

comment:3 by rmunn@…, 19 years ago

Bug also manifests with Python 2.4.1, PostgreSQL 7.4.8.

comment:4 by rmunn@…, 19 years ago

It seems django/models/auth.py isn't getting loaded properly anymore: adding

        from django.core import meta
        raise AssertionError, 'Installed models: %s' % (meta.get_installed_model_modules(),)

into the middle of User.get_and_delete_messages() produced:

There's been an error:

Traceback (most recent call last):

  File "/home/rmunn/projects/django-svn/django/core/handlers/base.py", line 62, in get_response
    return callback(request, **param_dict)

  File "/home/rmunn/projects/django-svn/django/views/admin/main.py", line 50, in index
    c = Context(request, {'title': 'Site administration'})

  File "/usr/lib/python2.4/site-packages/django/core/extensions.py", line 14, in __init__
    self['messages'] = request.user.get_and_delete_messages()

  File "/home/rmunn/projects/django-svn/django/models/auth.py", line 128, in get_and_delete_messages
    raise AssertionError, 'Installed models: %s' % (meta.get_installed_model_modules(),)

AssertionError: Installed models: [<module 'django.models.polls' from '/usr/lib/python2.4/site-packages/learndjango/apps/polls/models/polls.pyc'>]

Note how there's only one entry in that list, and django.models.auth isn't in the list at all.

comment:5 by Adrian Holovaty, 19 years ago

Summary: Admin unavailable after upgrade to revision 503 (works in 502)Admin unavailable in development server after [503]

comment:6 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [504]) Fixed #322 -- 'django-admin runserver' no longer validates models.

comment:7 by rmunn@…, 19 years ago

Summary: Admin unavailable in development server after [503]Admin unavailable after upgrade to revision 503 (works in 502)

Interesting. If I comment out the validate() call, [503] works. No real surprises there. If I add the raise AssertionError statement from my previous comment, I can see that django.models.auth and django.models.core are properly loaded by the time I reach User.get_and_delete_messages(). However, if I then insert:

        from django.core import meta
        print 'Installed models:', meta.get_installed_model_modules()

just below the commented-out validate() call, it only shows one module, django.models.polls. And the bug also starts manifesting again since django.models.auth didn't get installed.

The proximate cause of the bug, therefore, is calling meta.get_installed_model_modules() before starting the server. Why that makes a difference, I don't yet know.

comment:8 by rmunn@…, 19 years ago

Summary: Admin unavailable after upgrade to revision 503 (works in 502)Admin unavailable in development server after [503]

Oops, didn't see the bug had been closed before I posted my update. Changed summary back to what it was.

comment:9 by rmunn@…, 19 years ago

priority: highnormal
Resolution: fixed
Severity: criticalenhancement
Status: closedreopened
Summary: Admin unavailable in development server after [503][patch] Admin unavailable in development server after [503]

The code in django/models/__init__.py should be run before calling meta.get_installed_model_modules() so that it has a chance to import django.models.auth and django.models.core. The following patch against [504] will fix the problem and allow validation to be done in runserver again:

Index: django/core/management.py
===================================================================
--- django/core/management.py   (revision 504)
+++ django/core/management.py   (working copy)
@@ -494,6 +494,7 @@

 def validate():
     "Validates all installed models."
+    import django.models
     from django.core import meta
     e = ModelErrorCollection()
     module_list = meta.get_installed_model_modules()
@@ -545,6 +546,8 @@
     def inner_run():
         from django.conf.settings import SETTINGS_MODULE
         print "\nStarting server on port %s with settings module %r." % (port, SETTINGS_MODULE)
+        print "Validating models..."
+        validate()
         print "Go to http://127.0.0.1:%s/ for Django." % port
         print "Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows)."
         try:

comment:10 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: reopenedclosed

(In [505]) Fixed #322 -- Development server now calls validate() again. Thanks, rmunn

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