Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1930 (closed defect: fixed)

Opened 11 years ago

Last modified 10 years ago

[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

tg-devtools.patch Download (863 bytes) - added by Gustavo 11 years ago.
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 Download (1.9 KB) - added by Gustavo 11 years ago.
The updated patch for tg.config

Change History

Changed 11 years ago by Gustavo

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

comment:1 Changed 11 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 11 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".

Changed 11 years ago by Gustavo

The updated patch for tg.config

comment:3 in reply to: ↑ 2 Changed 11 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: user

I think the references to "user" should be replaced by "user_class".

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

comment:4 Changed 11 years ago by mramm

  • Milestone set to 2.0-preview-3

comment:5 Changed 11 years ago by mramm

  • Status changed from new to assigned

comment:6 Changed 11 years ago by mramm

  • Status changed from assigned to closed
  • Resolution set to fixed

Patches committed.

comment:7 Changed 10 years ago by anonymous

  • Milestone 1.9.7a4 deleted

Milestone 1.9.7a4 deleted

Note: See TracTickets for help on using tickets.