Opened 7 years ago

Closed 7 years ago

#7768 closed (duplicate)

r 'str' object is not callable in base.py

Reported by: William Martinez Pomares <wmartinez@…> Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

Working with SVN revision 7930, following the tutorial, up to the place where the votes view is created.
The line in the vote() method

   return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(p.id,)))

fails presenting a debug page that says:

TypeError at /polls/1/results/
'str' object is not callable
Request Method: 	GET
Request URL: 	http://127.0.0.1:8000/polls/1/results/
Exception Type: 	TypeError
Exception Value: 	'str' object is not callable
Exception Location: 	C:\Python25\lib\site-packages\django\core\handlers\base.py in get_response, line 85

I have found some relates issues (like 4700) that point to the INSTALLED_APPS settings and how the django.contrib.auth affects the get_response. I tried eliminating that application and still the error shows.
If using HttpResponseRedirect without the reverse (hardcoding the url) it fails too. If using render_to_response() instead, it works.

Another relate ticket may be 6442, but that one happens when the import error occurs. In this case the imports are ok in views.py, it is the HttpResponseRedirect that may have problems.

William Martinez.

Change History (12)

comment:1 Changed 7 years ago by William Martinez Pomares <wmartinez@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

An update.

I found out a problem in the views.py, the actual results() method that is the one called when HttpResponseRedirect is executed (url is '/polls/3/results/'). It had a problem in the name, so it was not found. That may not cause an import issue like in ticket 6442 but it will probably raise an exception. I was about to set this ticket as a duplicaet of 6442, but it is slightly different in the cause. Still, it may be resolved around the same command line.

Here, as in 6442, the error should indicate the view was not found instead of the misleading TypeError at base.py.

William.

comment:2 Changed 7 years ago by adrian

  • Description modified (diff)

(Fixed formatting in description)

comment:3 follow-up: Changed 7 years ago by ericholscher

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

Ask on django-users, more than likely the tutorial is correct.

comment:4 in reply to: ↑ 3 Changed 7 years ago by bengan

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Replying to ericholscher:

Ask on django-users, more than likely the tutorial is correct.

But not for me. I have the same issue. Exactly the same.

comment:5 Changed 7 years ago by ubernostrum

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

The tutorial is correct; if you read the comments above you'll see that the original person who filed this ticket had an error of his own while following the tutorial, rather than an error due to the code in the tutorial. As Eric suggested, ask on django-users for further help rather than needlessly churning the ticket tracker.

comment:6 Changed 7 years ago by William Martinez <wmartinez@…>

Hello.
I'm the original person that wrote the ticket. It is NOT a tutorial problem I talked about, so this is not a django-users question.
Please read carefully:

In following the tutorial, I wrote something wrong, so it was supposed to fail.
I expected to see an error of method or view not found. Instead I saw another error, the one " 'str' object not callable' at base.py.
Following other bugs, it seems it actually raise an exception that is caught and ignored, leading to an error later on at base.py.
Bug 6442 explains this.

So, in summary:
-> If you have a typo in the view method, it will not tell you that. It will throw a misleading exception " 'str' object not callable' at base.py.
THAT, is the bug.

I won't reopen the ticket, if you fix bug 6442 it may get fixed.
Thanks.
William Martinez.

comment:7 Changed 7 years ago by hannnndy <web@…>

  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Summary changed from HttpResponseRedirect causes a TypeError 'str' object is not callable in base.py to r 'str' object is not callable in base.py

why this error happens and how should i solve it

comment:8 Changed 7 years ago by dc

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

Please ask on django-users for help.

comment:9 Changed 7 years ago by kmtracey

Replying to hannnndy <web@parsitech.com>:

why this error happens and how should i solve it

I don't know, because you have provided no information about what you are doing. The reported instances of this error are all user error, so tracking down what is going wrong is best done on django-users, where there are more people reading and likely to help, than in the ticket tracker. Or read through the comments here and in #6442 and see if you have made an error similar to others that led to this error message. The bug in Django here is that this error message is not very helpful in tracking down what your real error is, and that is covered by #6442.

comment:10 Changed 7 years ago by ziofunk

  • Resolution worksforme deleted
  • Status changed from closed to reopened

comment:11 Changed 7 years ago by ziofunk

The same wrong error message is returned in a situation that is not described in #6442.
I have an urls.py inside my application. I have it correctly included in the project urls.py. When I use the first argument to the patterns() function to specify a prefix to be applied to each view function, if the prefix is mispelled I get the correct error saying that the module does not exist. When I don't put any prefix I get the wrong error message reported in this bug:

Exception Value: 'str' object is not callable
Exception Location: C:\Python25\lib\site-packages\django\core\handlers\base.py in get_response, line 85

comment:12 Changed 7 years ago by kmtracey

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

While your exact reproduction scenario may differ from what is detailed in #6442, it sounds to me like the fix proposed for #6442 would cover this case as well. The fix suggested there is:

"I suggest that urlresolver would raise an exception on invalid look-ups."

If that fix were in place, then the resolve() call would raise an error instead of returning a string, and you'd never get to the point where subsequent code tried to call a string object.

So I'd say your scenario is just a different way of tripping over the same bug -- you just have a different way of injecting an invalid lookup into your urls.py. If you'd like to ensure your case is considered when #6442 is fixed, the right place to mention it is in #6442 itself, not here. We only need one open ticket to track improving this error situation.

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