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

Opened 12 years ago

Last modified 11 years ago

tg-admin causing problems with SQL Object and different registry for classes when using a ForeignKey

Reported by: godoy Owned by: anonymous
Priority: low Milestone: 1.0.x bugfix
Component: tg-admin (non-toolbox) Version: 1.0
Severity: major Keywords:
Cc:

Description

I have a project that uses other projects to provide some functionality. Due to how SQL Object register classes I need to have some classes declared in a different registry (a kind of namespace).

If I use "sqlobject-admin sql sql" I can see the output perfectly fine. If I use "tg-admin sql sql" I get a problem saying that there was no <some class> declared on the default registry. The thing is that there can't be that class on the default registry because it would clash with the same class from another application.

Somehow tg-admin is mangling the class declaration.

Commands that can be used to test the declaration:

(problem) tg-admin sql sql (works) sqlobject-admin sql -m project.model -c postgres://user:password@host/dbname

Outputs:

(problem)

% tg-admin sql sql
Using database URI sqlite:///home/godoy/empresa/clientes/selco/ged/devdata.sqlite
Traceback (most recent call last):
  File "/usr/bin/tg-admin", line 7, in ?
    sys.exit(
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/turbogears/command/base.py", line 389, in main
    command.run()
  File "/home/godoy/desenvolvimento/python/TurboGears/1.0/turbogears/command/base.py", line 144, in run
    command.the_runner.run(sys.argv)
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/manager/command.py", line 102, in run
    runner.run()
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/manager/command.py", line 233, in run
    self.command()
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/manager/command.py", line 508, in command
    print cls.createTableSQL().strip() + ';\n'
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/main.py", line 1344, in createTableSQL
    sql = conn.createTableSQL(cls)
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/dbconnection.py", line 531, in createTableSQL
    return ('CREATE TABLE %s (\n%s\n)' %
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/dbconnection.py", line 535, in createColumns
    columnDefs = [self.createIDColumn(soClass)] \
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/sqlite/sqliteconnection.py", line 192, in createColumn
    return col.sqliteCreateSQL()
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/col.py", line 744, in sqliteCreateSQL
    other = findClass(self.foreignKey)
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/classregistry.py", line 135, in findClass
    return registry(class_registry).getClass(name)
  File "/usr/local/lib/python2.4/site-packages/SQLObject-0.7.2a_r2023-py2.4.egg/sqlobject/classregistry.py", line 106, in getClass
    raise KeyError(
KeyError: 'No class Usuario found in the registry [default] (these classes exist: SQLObject, SQLObjectVersionTable)'

(works)

% sqlobject-admin sql -m ged.model -c postgres://godoy:teste@localhost/neo
CREATE TABLE administrativo.empresas (
    id SERIAL PRIMARY KEY,
    incluido_por_id INT NOT NULL, CONSTRAINT incluido_por_id_exists FOREIGN KEY (incluido_por_id) REFERENCES usuarios (id) ON DELETE RESTRICT,
    incluido_em TIMESTAMP,
    alterado_por_id INT NOT NULL, CONSTRAINT alterado_por_id_exists FOREIGN KEY (alterado_por_id) REFERENCES usuarios (id) ON DELETE RESTRICT,
    alterado_em TIMESTAMP
);
;;

CREATE TABLE tg_group (
    id SERIAL PRIMARY KEY,
    group_name VARCHAR(16) NOT NULL UNIQUE,
    display_name VARCHAR(255),
    created TIMESTAMP
);
CREATE TABLE tg_user_group (
group_id INT NOT NULL,
user_id INT NOT NULL
);
CREATE TABLE tg_group_permission (
group_id INT NOT NULL,
permission_id INT NOT NULL
);;

CREATE TABLE permission (
    id SERIAL PRIMARY KEY,
    permission_name VARCHAR(16) NOT NULL UNIQUE,
    description VARCHAR(255)
);
;;

CREATE TABLE tg_user (
    id SERIAL PRIMARY KEY,
    user_name VARCHAR(16) NOT NULL UNIQUE,
    email_address VARCHAR(255) NOT NULL UNIQUE,
    display_name VARCHAR(255),
    password VARCHAR(40),
    created TIMESTAMP
);
;;

CREATE TABLE usuarios (
    id SERIAL PRIMARY KEY,
    login VARCHAR(16) NOT NULL UNIQUE,
    aprova_pagamento BOOL
);
;;

CREATE TABLE visit (
    id SERIAL PRIMARY KEY,
    visit_key VARCHAR(40) NOT NULL UNIQUE,
    created TIMESTAMP,
    expiry TIMESTAMP
);
;;

CREATE TABLE visit_identity (
    id SERIAL PRIMARY KEY,
    visit_key VARCHAR(40) NOT NULL UNIQUE,
    user_id INT
);
;;

Attachments

model.py Download (3.9 KB) - added by godoy 12 years ago.
Model that can be used to test the problem

Change History

Changed 12 years ago by godoy

Model that can be used to test the problem

comment:1 Changed 12 years ago by alberto

  • Milestone changed from 1.0.1 to 1.0.2

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

  • Milestone changed from 1.0.3 to 1.1

comment:4 Changed 11 years ago by faide

  • Priority changed from normal to low
  • Milestone changed from 1.1 to 1.1.1

Jorge, do you still have the problem? Is it still relevant for you?

comment:5 Changed 11 years ago by godoy

I will test if the problem is still there. I haven't been using tg-admin because of the problem.

If it is still there, it is still relevant because it prevents using the tool when you have multiple schemas on your database and then renders tg-admin as useless (that was my case).

I'll post back here after testing it again.

comment:6 Changed 11 years ago by godoy

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

The attached file works with current TG (svn. 4688 - 1.0 branch).

Today I have more complex model files that fails, though. I am importing classes from other projects. They run fine, but neither TG nor SO can correctly create the SQL commands for this database.

I consider this bug fixed, since the file attached here worked.

comment:7 Changed 11 years ago by kskuhlman

  • Milestone changed from 1.6 to 1.0.x bugfix
Note: See TracTickets for help on using tickets.