TypeError: No object (name: request) has been registered for this thread

900 views
Skip to first unread message

Tim Black

unread,
Sep 30, 2011, 9:03:34 PM9/30/11
to turbo...@googlegroups.com
I'm getting this error message when running my tests:

ERROR: Failure: TypeError (No object (name: request) has been registered for this thread)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/nose/loader.py", line 390, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/nose/importer.py", line 39, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/nose/importer.py", line 86, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/projects/projects/controllers/project/__init__.py", line 24, in <module>
    from projects.controllers.project.bill import BillController
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/projects/projects/controllers/project/bill.py", line 26, in <module>
    class BillController(BaseController):
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/projects/projects/controllers/project/bill.py", line 28, in BillController
    allow_only = is_manager or is_client
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/repoze/what/plugins/pylonshq/utils.py", line 74, in <lambda>
    Predicate.__nonzero__ = lambda self: self.is_met(request.environ)
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/paste/registry.py", line 137, in __getattr__
    return getattr(self._current_obj(), attr)
  File "/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/paste/registry.py", line 197, in _current_obj
    'thread' % self.____name__)
TypeError: No object (name: request) has been registered for this thread

----------------------------------------------------------------------
Ran 1 test in 0.486s

FAILED (errors=1)

bootstrap.py creates a user named 'manager', puts him in the 'managers' group and gives that group the 'manage' permission.  is_manager checks to see if the user has the 'manage' permission.

projects/tests/__init__.py says:

    The projects application instance (``self.app``) set up in this test
    case (and descendants) has authentication disabled, so that developers can
    test the protected areas independently of the :mod:`repoze.who` plugins
    used initially. This way, authentication can be tested once and separately.
   
All tests of secure controllers contain code like this:

        environ = {'REMOTE_USER': 'manager'}
        response = self.app.get('/project2/bill/view/1', extra_environ=environ)

The relevant ticket was closed with a 'worksforme' status.

What could be causing the error above?

Tim



Michael Pedersen

unread,
Oct 2, 2011, 10:24:34 PM10/2/11
to turbo...@googlegroups.com
Well, what the page is saying is that, for some reason, your 'self.app.get' is not generating a request object. I don't have a reason why, though. At the least, I need to ask the following of you:

1. Which version of TurboGears are you running these tests with?
2. Which version of TurboGears did you start with (need to check to see if maybe we missed something during the upgrade process)
3. If possible, is there a place where we can read the code and try it out for ourselves?

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.



--
Michael J. Pedersen
My IM IDs: Jabber/pede...@icelus.tzo.com, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/pederm...@hotmail.com
My Online Resume: http://www.icelus.org/
Twitter: pedersentg

Tim Black

unread,
Oct 4, 2011, 1:07:31 AM10/4/11
to turbo...@googlegroups.com
On 10/02/2011 09:24 PM, Michael Pedersen wrote:
Well, what the page is saying is that, for some reason, your 'self.app.get' is not generating a request object. I don't have a reason why, though. At the least, I need to ask the following of you:

1. Which version of TurboGears are you running these tests with?
TurboGears 2.1.2.  Sorry I didn't say that in my original email.

2. Which version of TurboGears did you start with (need to check to see if maybe we missed something during the upgrade process)
I've upgraded this app's virtualenv through the following versions of TurboGears:  2.1b2, 2.1rc1, 2.1.1, 2.1.2.  I'm not sure, but I think the tests started failing after the upgrade from 2.1.1 to 2.1.2.

3. If possible, is there a place where we can read the code and try it out for ourselves?
The code is available at http://alwaysreformed.com/publicdocs/tg21env-dev.7z, but I had to remove the version control repository, databases and some usernames, passwords, and cookie/beaker secrets because I can't make those public.  If you need those I'm willing to share them privately.

Thank you for being willing to help.

Tim

Alessandro Molina

unread,
Oct 4, 2011, 4:11:34 AM10/4/11
to turbo...@googlegroups.com
On Tue, Oct 4, 2011 at 7:07 AM, Tim Black <t...@alwaysreformed.com> wrote:
> I've upgraded this app's virtualenv through the following versions of
> TurboGears:  2.1b2, 2.1rc1, 2.1.1, 2.1.2.  I'm not sure, but I think the
> tests started failing after the upgrade from 2.1.1 to 2.1.2.
>

Have you tested it with a clean virtualenv installed from scratch with 2.1.2?
If you upgraded it might be that you ended up having an unexpected
combination of libraries installed.

Tim Black

unread,
Oct 6, 2011, 10:51:04 AM10/6/11
to turbo...@googlegroups.com

I tried doing that with TG 2.1.2 and TG 2.1.3, as follows:

# TG 2.1.2 attempt:
virtualenv --no-site-packages tg212
cd tg212/
source bin/activate
easy_install turbogears2==2.1.2 tg.devtools==2.1.2
# copied in unmodified projects (2.1.2 app) folder from
http://alwaysreformed.com/publicdocs/tg212.7z
cd projects/
python setup.py develop
python projects/tests/nosy.py
# pkg_resources.VersionConflict: (ToscaWidgets 0.8.7.1dev-20111004
(/home/tim/Documents/MyWebPages/arwd/projects/tg212/lib/python2.6/site-packages/ToscaWidgets-0.8.7.1dev_20111004-py2.6.egg),
Requirement.parse('ToscaWidgets>0.9.7'))
easy_install -U toscawidgets
python projects/tests/nosy.py
# pkg_resources.DistributionNotFound: tgext.crud>=0.3.7
# Added tgext.crud>=0.3.7 to requirements
python setup.py develop
python projects/tests/nosy.py
# ImportError: No module named genshi.filters
# Added Genshi to requirements
python setup.py develop
python projects/tests/nosy.py
# ImportError: No module named pylonshq
# Added repoze.what_pylons to requirements
python setup.py develop
python projects/tests/nosy.py
# TypeError: No object (name: request) has been registered for this thread

# TG 2.1.3 attempt:
virtualenv --no-site-packages tg213
cd tg213/
source bin/activate
easy_install tg.devtools
# copied in projects (app) folder from
http://alwaysreformed.com/publicdocs/tg21env-dev-2.1.3.7z, with TG 2.1.3
quickstart template diffs merged in
cd projects
python setup.py develop
python projects/tests/nosy.py


TypeError: No object (name: request) has been registered for this thread

I tried all the following but still got the same error after trying each
one:
� I commented out all code in the projects/tests folder except that in
nosy.py.
� I temporarily deleted all files & folders in the projects/tests
directory except nosy.py. So, I think the error is not generated by the
tests' call to self.app.get.
� I ran `nosetests` without using nosy.py.

If I comment out line 28 of projects/controllers/project/bill.py, which
appears in the traceback, the same error appears, but instead of listing
line 28, the traceback lists:

File
"/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/projects/projects/controllers/project/bill.py",
line 32, in BillController
@require(is_client or is_manager)

If I comment out all the lines like @require(is_client or is_manager) in
that file, then the traceback reports the same error, generated from
these different lines, which still indicate the problem is that
"request" is missing:

File
"/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/projects/projects/widgets/tasks_manage.py",
line 19, in TaskTreeGridManage
JSLink(link=url('/javascript/jquery.jqGrid-%s/js/i18n/grid.locale-en.js'
% version)),
File
"/home/tim/Documents/MyWebPages/arwd/projects/tg21env-dev/lib/python2.6/site-packages/tg/controllers/util.py",
line 91, in url
base_url = pylons.request.environ['SCRIPT_NAME'] + base_url

So my main question is, how can I properly instantiate the "request"
variable when (or in terms of execution order, before) running my tests?

In case this is a dependency problem, I did a visual comparison of my TG
2.1.2 virtualenv's site-packages directory with the list here
http://www.turbogears.org/2.1/downloads/2.1.2/ and found my virtualenv
is missing these packages:

AddOns-0.7.zip
BytecodeAssembler-0.6.zip
Chameleon-1.3.0-rc1.tar.gz
DecoratorTools-1.8.zip
Extremes-1.1.1.zip
Jinja2-2.6.tar.gz
Kajiki-0.3.4.tar.gz
Mako-0.5.0.tar.gz
PEAK-Rules-0.5a1.dev-r2686.tar.gz
PasteDeploy-1.3.4.tar.gz
PasteScript-1.7.4.2.tar.gz
Pygments-1.4.tar.gz
SymbolType-1.0.zip
TurboJson-1.3.1.tar.gz
TurboJson-1.3.2.tar.gz
TurboKid-1.0.5.tar.gz
chameleon.core-1.0.3.tar.gz
chameleon.genshi-1.0b4.tar.gz
coverage-3.5.1.tar.gz
coverage-3.5.tar.gz
decorator-3.3.2.tar.gz
elementtree-1.2.7-20070827-preview.zip
hashlib-20081119.zip
kid-0.9.6.tar.gz
ordereddict-1.1.tar.gz
pysqlite-2.6.3.tar.gz
pytz-2011g.zip
simplegeneric-0.7.zip
simplegeneric-0.8.zip
simplejson-2.2.1.tar.gz
sourcecodegen-0.6.14.tar.gz
sprox-0.7b1.tar.gz
tgext.admin-0.3.11.tar.gz
tgext.crud-0.3.12.tar.gz
tw.dojo-0.9.9.tar.gz
uuid-1.30.tar.gz
wsgiref-0.1.2.zip
zope.component-3.10.0.tar.gz
zope.event-3.5.0-1.tar.gz
zope.i18n-3.7.4.tar.gz
zope.i18nmessageid-3.5.3.tar.gz
zope.interface-3.6.3.tar.gz
zope.schema-3.8.0.tar.gz

My virtualenv has these packages that are not in the download list above:

concurrent
devtools
distribute-0.6.10-py2.6.egg
distribute-0.6.10-py2.6.egg-info
docutils-0.7-py2.6.egg
futures
marrow
marrow.mailer-4.0.0b3-py2.6.egg-info
marrow.util-1.2.0-py2.6.egg-info
migrate
PasteScript-1.7.3-py2.6.egg-info
pip-0.7.2-py2.6.egg-info
pygments
Pygments-1.4-py2.6.egg-info
repoze.tm2-1.0a5-py2.6.egg
repoze.what_quickstart-1.0.6-py2.6.egg
repoze.who_friendlyform-1.0.4-py2.6.egg
setuptools
simplejson-2.1.6-py2.6.egg-info
sqlalchemy_migrate-0.7.1-py2.6.egg-info
tgext.menu-1.0b3-py2.6.egg
tgext.menu-1.0rc1-py2.6.egg
turbomail
TurboMail-3.0.3-py2.6.egg-info
tw.jquery-0.9.9-py2.6.egg
tw.jquery-0.9.10-py2.6.egg-info
tw.uitheme-0.1a0-py2.6.egg
tw.uitheme-0.2.2-py2.6.egg-info
tw2.core-2.0b4-py2.6.egg
tw2.devtools-2.0b5-py2.6.egg
tw2.dynforms-2.0a2-py2.6.egg
tw2.forms-2.0b4-py2.6.egg
tw2.sqla-2.0a1-py2.6.egg
zope.interface-3.6.5-py2.6.egg-info
zope.sqlalchemy-0.4-py2.6.egg

I need some direction--which packages should I try upgrading, if any?
Should I try installing/upgrading to all of the ones in the official
package index list?

I've used pip in this virtualenv; could that be a problem?

Thanks again for your help!

Tim

timblack1

unread,
Jan 4, 2012, 5:08:57 AM1/4/12
to turbo...@googlegroups.com
These changes made the errors go away:

- @require(is_client or is_manager)
+ @require(Any(is_client, is_manager))

- JSLink(link=url('/javascript/jquery.jqGrid-%s/js/i18n/grid.locale-en.js'
% version)),
+ JSLink(link='/javascript/jquery.jqGrid-%s/js/i18n/grid.locale-en.js'
% version),

I'm unsure whether I should use url() in widget definitions.  I get the above error when I use url() and import the widget when the app loads (outside a controller method, before a request hits the app), so I've removed url() from my widget code.  But is url() needed in the widget code?

Tim

Alessandro Molina

unread,
Jan 4, 2012, 6:01:59 AM1/4/12
to turbo...@googlegroups.com
On Wed, Jan 4, 2012 at 11:08 AM, timblack1 <timb...@gmail.com> wrote:
> I'm unsure whether I should use url() in widget definitions.  I get the
> above error when I use url() and import the widget when the app loads
> (outside a controller method, before a request hits the app), so I've
> removed url() from my widget code.  But is url() needed in the widget code?

Inside widgets you should use lurl instead of url.
lurl calls are processed at render time instead of call time so they
avoid access to request outside a request.

Christoph Zwerschke

unread,
Jan 4, 2012, 7:03:00 AM1/4/12
to turbo...@googlegroups.com

Just noticed one peculiarity concerning this matter which is the "link"
parameter of resource widgets like CSSLink: When setting this parameter,
you should use neither url() nor lurl(), because ToscaWidgets already
does this for you and breaks lurl(). For all other parameters, which are
usually referenced and thereby stringified in the widget templates,
lurl() is the proper choice.

-- Christoph

Tim Black

unread,
Jan 4, 2012, 12:21:39 PM1/4/12
to turbo...@googlegroups.com
Thanks, Christoph; my issue was the specific case of using the "link"
parameter, so your answer solves my problem. I think, then, that these
docs need to be updated accordingly:
http://www.turbogears.org/2.1/docs/main/ToscaWidgets/forms.html?highlight=csslink.

Tim

Christoph Zwerschke

unread,
Jan 4, 2012, 1:33:00 PM1/4/12
to turbo...@googlegroups.com
Am 04.01.2012 18:21, schrieb Tim Black:
> I think, then, that these docs need to be updated accordingly:
> http://www.turbogears.org/2.1/docs/main/ToscaWidgets/forms.html

That's true, I have just created a ticket for that:
https://sourceforge.net/p/turbogears2/tickets/137/

-- Christoph

Reply all
Reply to author
Forward
0 new messages