Opened 10 years ago

Closed 10 years ago

#322 closed enhancement (fixed)

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

Reported by: jbennett@… Owned by: adrian
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: UI/UX:

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 Changed 10 years ago by garthk@…

+1

2.4.1, sqlite3

comment:2 Changed 10 years ago by matt@…

  • Summary changed from Admin unavailable after upgrade to revision 503 to Admin 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 Changed 10 years ago by rmunn@…

Bug also manifests with Python 2.4.1, PostgreSQL 7.4.8.

comment:4 Changed 10 years ago by rmunn@…

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 Changed 10 years ago by adrian

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

comment:6 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:7 Changed 10 years ago by rmunn@…

  • Summary changed from Admin unavailable in development server after [503] to 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 Changed 10 years ago by rmunn@…

  • Summary changed from Admin unavailable after upgrade to revision 503 (works in 502) to 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 Changed 10 years ago by rmunn@…

  • priority changed from high to normal
  • Resolution fixed deleted
  • Severity changed from critical to enhancement
  • Status changed from closed to reopened
  • Summary changed from Admin unavailable in development server after [503] to [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 Changed 10 years ago by adrian

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

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

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