Ticket #1930 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[Patch] Identity-related models with non-default names won't work with the SQLAlchemy auth backend

Reported by: Gustavo Assigned to: 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

tg-devtools.patch (0.8 kB) - added by Gustavo on 08/07/08 13:02:22.
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
tg-trunk.patch (1.9 kB) - added by Gustavo on 08/10/08 11:28:58.
The updated patch for tg.config

Change History

08/07/08 13:02:22 changed by Gustavo

  • attachment tg-devtools.patch added.

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

08/07/08 13:03:16 changed 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.

(follow-up: ↓ 3 ) 08/07/08 17:57:03 changed 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".

08/10/08 11:28:58 changed by Gustavo

  • attachment tg-trunk.patch added.

The updated patch for tg.config

(in reply to: ↑ 2 ) 08/10/08 11:29:37 changed 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?: user }}} I think the references to "user" should be replaced by "user_class".

This is fixed in the updated version of tg-trunk.patch

08/10/08 11:46:46 changed by mramm

  • milestone set to 2.0-preview-3.

08/10/08 11:47:05 changed by mramm

  • status changed from new to assigned.

08/10/08 21:36:13 changed by mramm

  • status changed from assigned to closed.
  • resolution set to fixed.

Patches committed.

12/10/08 12:39:58 changed by

  • milestone deleted.

Milestone 1.9.7a4 deleted