Opened 15 years ago

Closed 15 years ago

#12494 closed (invalid)

'module' object has no attribute when accessing settings

Reported by: Phoebe Bright Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This was working in 1.1 but since updating to svn version I get the following error when referencing settings values. Is there a new way of referencing settings? Might be linked to problem with decorators described. Can go back to earlier version if this is already in hand but wanted to record in case not.

eg.
from django.conf import settings (also tried just import settings)
print settings.FIRSTWEEKDAY

Works fine in shell
Works fine in some views in others get UnboundLocalError: local variable 'settings' referenced before assignment - if I added the decorator @transaction.commit_on_success, however it works again. If I use the @login_required decorator to see if it's decorators that's fixing it, I get AttributeError: 'MethodDecoratorAdaptor' object has no attribute 'func_code' and this error also appears on some other pages which were previously working.

Fails in api.py module with traceback below:
urls.py

urlpatterns += patterns('libs.api',
    url(r'^timeline/tweet/xml/(?P<filter_field>\w+)/(?P<filter_value>\w+)/$','timeline_tweet_xml', name='timeline_tweet_xml'),



Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 651, in __call__
    return self.application(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 141, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 165, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/base.py", line 99, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/phoebebr/Development/tinycomms/libs/api.py", line 151, in timeline_tweet_xml
    print settings.FIRSTWEEKDAY
AttributeError: 'module' object has no attribute 'FIRSTWEEKDAY'

Change History (1)

comment:1 by Luke Plant, 15 years ago

Resolution: invalid
Status: newclosed

There is not enough information here to work out if this is a bug in Django or in your code. The UnboundLocalError sounds almost certainly like a problem in your code - like you have a line settings = within a function somewhere, while earlier in the function it is attempting to use the global 'settings' module.

I'm closing INVALID - please re-open if you can produce and attach a minimal test case that shows the problem is in Django.

Thanks!

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