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

Opened 13 years ago

Last modified 13 years ago

[PATCH] identity subclasses cannot be loaded

Reported by: alberto@… Owned by: anonymous
Priority: high Milestone: 0.9
Component: Identity Version:
Severity: blocker Keywords:
Cc:

Description

As I've mentioned in this  post, using custom identity classes will lead to a "No database configuration found!" error when trying to start the web server or using tg-admin

The traceback Im getting is:

Traceback (most recent call last):
  File "/usr/bin/tg-admin", line 7, in ?
    sys.exit(
  File "/home/albertov/turbogears/turbogears/command/base.py", line 269, in main
    command.run()
  File "/home/albertov/turbogears/turbogears/command/base.py", line 175, in run
    mod = get_model()
  File "/home/albertov/turbogears/turbogears/util.py", line 76, in get_model
    package = __import__(get_package_name(), {}, {}, ["model"])
  File "/home/albertov/n50cpanel/n50cpanel/model.py", line 35, in ?
    class Usuario(TG_User):
  File "/home/albertov/turbogears/thirdparty/sqlobject/sqlobject/declarative.py", line 94, in __new__
    cls.__classinit__(cls, new_attrs)
  File "/home/albertov/turbogears/thirdparty/sqlobject/sqlobject/main.py", line 748, in __classinit__
    if not connection and not getattr(cls, '_connection', None):
  File "/home/albertov/turbogears/turbogears/database.py", line 124, in __get__
    self.set_hub()
  File "/home/albertov/turbogears/turbogears/database.py", line 142, in set_hub
    raise KeyError, "No database configuration found!"

I'm pretty sure it's cause because config.py imports my project's model and, as the database is configured in (dev|prod)cfg.py, the database configuration is not defined yet (update_config loads config.py BEFORE loading dev or prod).

I'm not too familiar with the new config style so I don't know what is the best way to solve it, I've tried a work around in the start-myproj.py script (described in the post, basically loads dev or prod before config.py is loaded) and works, the problem is that tg-admin shell continues to fail, so it's not a reasonable solution.

I'm not sure what's the gain from importing directly in config.py, it' worked flawlessly before, and, IMHO, importing from the config file directly, even if this "rough-edge" is smoothed, will open the door to all sort of problems...

As i've said, i'm not very familiar with this new confi style so don't take me too seriously.

Attachments

soprovider.patch Download (2.3 KB) - added by alberto@… 13 years ago.
A patch
soprovider.2.patch Download (3.3 KB) - added by alberto@… 13 years ago.
Patches config_py_tmpl accordingly to the new config style and add's logging to class loading

Change History

Changed 13 years ago by alberto@…

A patch

comment:1 Changed 13 years ago by alberto@…

I've patched soprovider so it dynamically loads the class from the modules specified in the config file (which removes the import from config.py). It works as expected, though it breaks the previous config style (which I think no-one was using, as this problem would have be reported before).

So, this patch changes config.py in this way:

import sdfsd.model
identity.soprovider.model.user=sdfsd.model.User
identity.soprovider.model.group=sdfsd.model.Group
identity.soprovider.model.permission=sdfsd.model.Permission

to

identity.soprovider.model.user="sdfsd.model.User"
identity.soprovider.model.group="sdfsd.model.Group"
identity.soprovider.model.permission="sdfsd.model.Permission"

Changed 13 years ago by alberto@…

Patches config_py_tmpl accordingly to the new config style and add's logging to class loading

comment:2 Changed 13 years ago by anonymous

  • Summary changed from identity subclasses cannot be loaded to [PATCH] identity subclasses cannot be loaded

Patch added, sorry for not waiting for anyone to comment on this proposed solution but I needed a fix ASAP as it was blocking my projects.

comment:3 Changed 13 years ago by kevin

I think this is the right thing to do, but I've sent a message to Jeff to see if he has any other opinions.

The idea with importing into the config file is that you catch typos in your classname right away, rather than when a URL is hit. But, to try and work around this seems messy.

comment:4 Changed 13 years ago by alberto@…

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

fixed at r676

Note: See TracTickets for help on using tickets.