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 #793 (closed defect: invalid)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Model designer "Create Tables" fails with multiple Join columns

Reported by: Philip Walls Owned by: anonymous
Priority: normal Milestone: 0.9a6
Component: Toolbox Version: 0.9a4
Severity: normal Keywords:
Cc: ronald@…

Description

If you try to create table from the model designer when a class has multiple ForeignKey? or *Join columns, designer/save_and_create fails. The problem appears to be that SQLObject is loading the model definitions from BOTH the model.py AND the tmp_model.py files and causing conflicts.

I solved this problem by not bothering with tmp_model, but I'm not sure if this will cause other kinds of problems. I'm not entirely sure why the author was making a copy of model.py before importing it. Maybe someone with more experience in this area can give their insight.

Example model

class Post(SQLObject):
    text = StringCol()
    parent = ForeignKey("Post")
    children = MultipleJoin("Post",joinColumn='parent_id')

Backtrace

  File "/path/to/turbogears/svn/turbogears/thirdparty/sqlobject/sqlobject/classregistry.py", line 91, in addClass
    '__file__', '(unknown)')))
ValueError: class Post is already in the registry (other class is <class 'testproject.model.Post'>, from the module testproject.model in /path/to/turbogears/Test-Project/testproject/model.pyc; attempted new class is <class 'testproject.tmp_model.Post'>, from the module testproject.tmp_model in /path/to/turbogears/Test-Project/testproject/tmp_model.py)

Attachments

modeldesigner_create_table_fail.patch Download (1.8 KB) - added by Philip Walls 13 years ago.
Patch to allow the Create Table feature of the model designer to work
modeldesigner_create_table_fail.2.patch Download (1.8 KB) - added by Philip Walls 13 years ago.
fixed version of patch for working with brand new models

Change History

Changed 13 years ago by Philip Walls

Patch to allow the Create Table feature of the model designer to work

comment:1 Changed 13 years ago by kevin

  • Cc ronald@… added
  • Milestone changed from 0.9a5 to 1.0b1

I'm going to defer this until Ronald has had a chance to look.

comment:2 Changed 13 years ago by Philip Walls

No word from Ronald yet about this problem. I have looked at this area of the model designer code and can't see any reason why the tmp_model was being created before doing a create table.

It was making a copy of the model.py and then building the create table syntax from that model instead of the original. Such a hack is not present in the SQLObject manager code, so I don't see any reason why it would be necessary in this scenario.

At this point, I am confident in the original patch I submitted. I have been using this patch on my TurboGears install for the past 4 days and have run into no problems.

comment:3 Changed 13 years ago by ronald@…

Hi Philip, sorry for being late at this...

The hack with the tmp file is there to support the following use case (which is MD's main scenario):

  • create a fresh project
  • configure your db
  • run tg-admin toolbox
  • create a model with modelDesigner
  • generate the code and create the tables
  • navigate to catwalk and start playing with you objects

Your patch breaks this scenario =(

Generating tables for existing models (or adding new classes to an exisisting model) is currently not fully supported

comment:4 Changed 13 years ago by Philip Walls

Ahh.. I see what you are saying. The reason you were using the temporary model is because the primary model is not re-imported when doing the "save and create tables" function, so you'd have to have an already complete model when you initialized the toolbox.

I was able to resolve this problem by simply reloading the model object after saving. I will attach a modified patch (single line different from previous) that fixes the problem you mentioned. I just tested the following:

  • quickstart a new project
  • modify the dev.cfg slightly and start toolbox
  • Create the model from the description of this ticket using the model designer
  • Click "Save and create tables"
  • Go in to Catwalk, add some rows

Everything worked great :)

Changed 13 years ago by Philip Walls

fixed version of patch for working with brand new models

comment:5 Changed 13 years ago by Philip Walls

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

Alright, I tested the above scenario _without_ my patch, and it worked fine. I guess the problem I was experiencing before was some kind of fluke. I'm going to go ahead and mark this bug invalid. Sorry for the confusion :-/

comment:6 Changed 13 years ago by kevin

  • Milestone changed from 1.0b1 to 0.9a6
Note: See TracTickets for help on using tickets.