Ticket #1930 (closed defect: fixed)
[Patch] Identity-related models with non-default names won't work with the SQLAlchemy auth backend
| Reported by: | Gustavo | Owned by: | mramm |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | TurboGears | Version: | trunk |
| Severity: | major | Keywords: | |
| Cc: |
Description
Try renaming, in your data model, 'User' by 'Member', or 'Group' by 'Team', or both. Then update your app_cfg.py file accordingly. Finally, run `paster setup-app development.ini' - you'll get an error like this:
AttributeError: 'module' object has no attribute 'User'
That's because of setup_sa_auth_backend() in tg.config. It assumes that self.model.User, self.model.Group and self.model.Permission exist, but they may exist under a different name.
With the proposed patch, our app_cfg.py files *must* define the following attributes in base_config.sa_auth: "user_class", "group_class" and "permission_class", so that we don't rely on "default" classes that may not exist.
Attachments
Change History
Changed 3 years ago by Gustavo
-
attachment
tg-devtools.patch
added
comment:1 Changed 3 years ago by Gustavo
- Summary changed from [Patch] Identity-related models won't work with the SQLAlchemy auth backend to [Patch] Identity-related models with non-default names won't work with the SQLAlchemy auth backend
comment:2 follow-up: ↓ 3 Changed 3 years ago by Gustavo
It also fixes a typo: base_config.sa_auth.user should be base_config.sa_auth.user_class
I think TG2 is using two different attributes for the same thing. If "base_config.sa_auth.user" is not defined, when you try to start the application you'll get an error like this:
Starting subprocess with file monitor
Traceback (most recent call last):
File "/home/gustavo/System/Pyenvs/tg2-dev/bin/paster", line 8, in <module>
load_entry_point('PasteScript==1.6.3', 'console_scripts', 'paster')()
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 79, in run
invoke(command, command_name, options, args[1:])
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 118, in invoke
exit_code = runner.run(args)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 213, in run
result = self.command()
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/serve.py", line 251, in command
relative_to=base, global_conf=vars)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/serve.py", line 278, in loadapp
**kw)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 204, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 225, in loadobj
return context.create()
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 625, in create
return self.object_type.invoke(self)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 110, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/util/fixtypeerror.py", line 57, in fix_call
val = callable(*args, **kw)
File "/home/gustavo/GLM/Projects/Animador-TG2/animador/config/middleware.py", line 38, in make_app
app = make_base_app(global_conf, full_stack=True, **app_conf)
File "/home/gustavo/Projeti/TG2/tg/config.py", line 304, in make_base_app
app = self.add_auth_middleware(app)
File "/home/gustavo/Projeti/TG2/tg/config.py", line 215, in add_auth_middleware
app = make_who_middleware(app, config, auth.user,
File "/home/gustavo/Projeti/TG2/tg/config.py", line 35, in __getattr__
raise AttributeError(name)
AttributeError: user
I think the references to "user" should be replaced by "user_class".
comment:3 in reply to: ↑ 2 Changed 3 years ago by Gustavo
Replying to Gustavo:
It also fixes a typo: base_config.sa_auth.user should be base_config.sa_auth.user_class
I think TG2 is using two different attributes for the same thing. If "base_config.sa_auth.user" is not defined, when you try to start the application you'll get an error like this:
Starting subprocess with file monitor Traceback (most recent call last): File "/home/gustavo/System/Pyenvs/tg2-dev/bin/paster", line 8, in <module> load_entry_point('PasteScript==1.6.3', 'console_scripts', 'paster')() File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 79, in run invoke(command, command_name, options, args[1:]) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 118, in invoke exit_code = runner.run(args) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/command.py", line 213, in run result = self.command() File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/serve.py", line 251, in command relative_to=base, global_conf=vars) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteScript-1.6.3-py2.5.egg/paste/script/serve.py", line 278, in loadapp **kw) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 204, in loadapp return loadobj(APP, uri, name=name, **kw) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 225, in loadobj return context.create() File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 625, in create return self.object_type.invoke(self) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/loadwsgi.py", line 110, in invoke return fix_call(context.object, context.global_conf, **context.local_conf) File "/home/gustavo/System/Pyenvs/tg2-dev/lib/python2.5/site-packages/PasteDeploy-1.3.2-py2.5.egg/paste/deploy/util/fixtypeerror.py", line 57, in fix_call val = callable(*args, **kw) File "/home/gustavo/GLM/Projects/Animador-TG2/animador/config/middleware.py", line 38, in make_app app = make_base_app(global_conf, full_stack=True, **app_conf) File "/home/gustavo/Projeti/TG2/tg/config.py", line 304, in make_base_app app = self.add_auth_middleware(app) File "/home/gustavo/Projeti/TG2/tg/config.py", line 215, in add_auth_middleware app = make_who_middleware(app, config, auth.user, File "/home/gustavo/Projeti/TG2/tg/config.py", line 35, in __getattr__ raise AttributeError(name) AttributeError: userI think the references to "user" should be replaced by "user_class".
This is fixed in the updated version of tg-trunk.patch
A patch to the default template, so that it includes the now mandatory configuration parameters. It also fixes a typo: base_config.sa_auth.user should be base_config.sa_auth.user_class