Problem with TG functional tests

47 views
Skip to first unread message

Christoph Zwerschke

unread,
Jun 12, 2013, 11:51:19 AM6/12/13
to TurboGears Trunk
I have just run into an ugly problem with TG 2.2.2 that you can
reproduce as follows:

* Quickstart a project
* Set in config/app_cfg.py:
base_config.sa_auth.authenticators = [('default', None)]
* Run paster setup-app
* Run nosestests

You get this error:
app = setup_auth(app, skip_authentication=skip_authentication,
**auth_args)
File "...\tg\configuration\auth.py", line 227, in setup_auth
return _AuthenticationForgerMiddleware(app, **who_args)
TypeError: __init__() got an unexpected keyword argument 'dbsession'

I think the problem is this:
When running the test, the app is configured with the same config object
multiple times. In the first run, in add_auth_middleware, the sqlauth
authenticator is created using create_default_authenticator(). In this
process, the "dbsession" parameter is removed from auth_args.
However, in the second run, the sqlauth authenticator is already setup
in the configuration, create_default_authenticator() will not be
executed, the "dbsession" parameter is not removed, and finally the
_AuthenticationForgerMiddleware will be called with that parameter which
it does not want to have.

The easiest way to fix this is to let _AuthenticationForgerMiddleware
ignore superfluous arguments. Any better ideas?

-- Christoph

Alessandro Molina

unread,
Jun 12, 2013, 12:25:51 PM6/12/13
to tg-trunk
I think that the issue is that configuration process should be idempotent, there are various cases in which this is not the true, but we should probably clean them to make avoid having AppConfig edit the configuration.

Probably changing
         auth_args = copy(self.sa_auth)
to a deepcopy might solve the issue by making so that the original authenticators list is not modified, but instead a copy of it is modified, so that calling again the configuration process leads to the same result.

I didn't actually try it, so I might be wrong, but I feel that the right solution should be making the config process idempotent :D





-- Christoph

--
You received this message because you are subscribed to the Google Groups "TurboGears Trunk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears-trunk+unsubscribe@googlegroups.com.
To post to this group, send email to turbogears-trunk@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears-trunk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Alessandro Molina

unread,
Jun 14, 2013, 3:15:30 AM6/14/13
to tg-trunk
I tried to tackle this yesterday night, but as soon as I made part of the configuration process idempotent things started collapsing due to the global nature of the config object.
Changing the configuration process to use self instead of tg.config to read/set values started to make multiple tests fail, it looks like some tests were working only because previous tests changed tg.config globally.

Alessandro Molina

unread,
Jun 14, 2013, 4:30:48 AM6/14/13
to tg-trunk
ok, https://github.com/TurboGears/tg2/commit/1c4da8da9fc5bc85023645b72f906d8c3132fc97#L1R888 should fix the issue.
It looks like it was introduced by the ('default', None) authenticator feature that changed the original list of authenticators in the case both the default and custom authenticators were defined.

Christoph Zwerschke

unread,
Jun 14, 2013, 8:49:08 AM6/14/13
to turbogea...@googlegroups.com
Am 14.06.2013 10:30, schrieb Alessandro Molina:
> https://github.com/TurboGears/tg2/commit/1c4da8da9fc5bc85023645b72f906d8c3132fc97#L1R888
> should fix the issue. It looks like it was introduced by the
> ('default', None) authenticator feature that changed the original
> list of authenticators in the case both the default and custom
> authenticators were defined.

Nice, thanks for looking into this. I'd like to backport the fix to the
2.2 branch, is that ok?

-- Christopg

Alessandro Molina

unread,
Jun 14, 2013, 10:03:47 AM6/14/13
to tg-trunk
Thanks, will update it soon, did the patch work for you?


--
You received this message because you are subscribed to the Google Groups "TurboGears Trunk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears-trunk+unsubscribe@googlegroups.com.
To post to this group, send email to turbogears-trunk@googlegroups.com.

Christoph Zwerschke

unread,
Jun 14, 2013, 10:18:29 AM6/14/13
to turbogea...@googlegroups.com
Am 14.06.2013 16:03, schrieb Alessandro Molina:
> Thanks, will update it soon, did the patch work for you?

Haven't tried it, since my projects are still using TG 2.2.

-- Christoph

Christoph Zwerschke

unread,
Jun 17, 2013, 12:27:26 PM6/17/13
to turbogea...@googlegroups.com
Just noticed that the patch for supporting a 'default' authenticator
entry, which was the main problem why the test failed, has not been
backported to 2.2 anyway, so it does not make much sense to backport
this fix either. I only noticed it because I used a patched version of
2.2 with 'default' authenticator support. But I'll upgrade to 2.3 now.

-- Christoph
Reply all
Reply to author
Forward
0 new messages