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 #1338 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

custom identity model classes break on Toolbox

Reported by: kov Owned by: anonymous
Priority: normal Milestone: 1.0.3
Component: Toolbox Version: 1.0
Severity: normal Keywords:
Cc:

Description

Bug reported on the Debian package ( http://bugs.debian.org/415909):

I do tg-admin quickstart, tell it to use 'identity' and get a model with
these classes:

  $ grep ^class model.py
  class Visit(SQLObject):
  class VisitIdentity(SQLObject):
  class Group(SQLObject):
  class User(SQLObject):
  class Permission(SQLObject):

so far so good, but after customizing them a bit[1], I noticed weird
behaviours in the toolbox.  It turns out that the toolbox has a
different, very personal idea of those tables:

  $ grep ^class turbogears/identity/soprovider.py
  class TG_VisitIdentity(SQLObject):
  class TG_Group(InheritableSQLObject):
  class TG_User(InheritableSQLObject):
  class TG_Permission(InheritableSQLObject):

This causes all sorts of funny misbehaviours when using the toolbox and
the application: tables created by the toolbox won't work with the
application (they'd miss the extra custom fields), but the toolbox won't
be able to edit the user tables created by the application (trying to
add a user gives me "An error occurred: global name 'identity' is
not defined").

Plus, there's no obvious way to recreate the database tables as 
"tg-admin sql create" will create broken user tables.  Here's a
work-around script for that:

#!/usr/bin/python

from os.path import *
import sys, inspect

import pkg_resources
pkg_resources.require("TurboGears")

import turbogears

# first look on the command line for a desired config file,
# if it's not on the command line, then
# look for setup.py in this directory. If it's not there, this script is
# probably installed
if len(sys.argv) > 1:
    turbogears.update_config(configfile=sys.argv[1],
        modulename="pec.config")
elif exists(join(dirname(__file__), "setup.py")):
    turbogears.update_config(configfile="dev.cfg",
        modulename="pec.config")
else:
    turbogears.update_config(configfile="prod.cfg",
        modulename="pec.config")

import MYNAMESPACE.model as pm
import sqlobject 
from sqlobject.inheritance import InheritableSQLObject

for item in pm.__dict__.values():
    if inspect.isclass(item) and issubclass(item, sqlobject.SQLObject) \
       and item != sqlobject.SQLObject and item != InheritableSQLObject:
        print "Recreating", item
        item.createTable(ifNotExists=True)

Ciao,

Enrico

[1]
I'm supposed to be able to do it.  It even says it in the User class
comment:
class User(SQLObject):
    """
    Reasonably basic User definition. Probably would want additional attributes.
    """

Enrico (the reporter) has given more information, including taking back one of the claims he did on the original bug report. Refer there if needed. I post his followup here for completeness:

> application (they'd miss the extra custom fields), but the toolbox won't
> be able to edit the user tables created by the application (trying to
> add a user gives me "An error occurred: global name 'identity' is
> not defined").

This was an error in my model: User uses identity to encrypt its
passwords, but there trivially was an 'import turbogears.identity as
identity' missing.

The rest of the bug stands, though: when one customizes the identity
tables, if toolbox is run before the application then it will create
incorrect identity tables in the database.

Change History

comment:1 Changed 12 years ago by kov

  • Component changed from Toolbox.Catwalk to Toolbox
  • Summary changed from custom identity model classes break on Toolbox (Catwalk) to custom identity model classes break on Toolbox

comment:2 Changed 12 years ago by alberto

  • Milestone changed from 1.0.2 to 1.0.3

comment:3 Changed 12 years ago by faide

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

Should be corrected now see r3203

please re-open if the problem is still present, but this was most certainly due to the config being not completely passed to the provider when the toolblox loaded...

Note: See TracTickets for help on using tickets.