Bug 205894

Summary: SQLObject does not determine Foreign Key dependencies
Product: [Fedora] Fedora Reporter: Toshio Kuratomi <toshio>
Component: python-sqlobjectAssignee: Luke Macken <lmacken>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: medium    
Version: 5CC: extras-qa, pfrields
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-09-12 02:51:01 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Small test case
none
Patch to give SQLObject Foreignkey dependency intelligence none

Description Toshio Kuratomi 2006-09-09 17:43:26 UTC
Description of problem:
I ran across this while using TurboGears and postgreSQL.

SQLObject does not determine what order it has to create or drop tables in. 
Instead, it appears to order alphabetically.  When using ForeignKey constraints
and a postgresql database, this can lead to problems as postgreSQL will raise an
exception when a foreign key references a table that does not exist yet.

Version-Release number of selected component (if applicable):
python-sqlobject-0.7.0-6

How reproducible:
Everytime.

Steps to Reproduce:
1. tg-admin quickstart
2. Download the attached model.py and replace the existing model.py with it
3. Edit dev.cfg to have a postgresql database URI
4. Create the empty postgresql database.
5. Run tg-admin sql create
  
Actual results:
Error is raised about non-existent table

Expected results:
All tables in the schema are created.

Additional info:
There are several upstream bugs reports in TurboGears and sqlobject trackers
that bear on this issue:
http://trac.turbogears.org/turbogears/ticket/279
http://sourceforge.net/tracker/index.php?func=detail&aid=1495030&group_id=74338&atid=540672

The attached patch is adapted from the turbogears ticket (I couldn't get the
patch there to apply directly so I regenerated it... Oddly, only the strip level
differs between my patch and the one attached to the bug but mine applies)

Using this patch, I can now create the database with the postgreSQL backend.

Comment 1 Toshio Kuratomi 2006-09-09 17:43:26 UTC
Created attachment 135910 [details]
Small test case

Comment 2 Toshio Kuratomi 2006-09-09 17:46:37 UTC
Created attachment 135911 [details]
Patch to give SQLObject Foreignkey dependency intelligence

This patch is adapted from the one in the TurboGears tracker.  I wasn't able to
find it in the upstream sqlobject tracker but I didn't search their mailing
list.  I've built it against the python-sqlobject devel branch and it resolves
the issue of creating tables in postgresql.

Comment 3 Toshio Kuratomi 2006-09-09 18:08:59 UTC
Found an SQLObject bug that addresses the issue even better than the previous one:
http://sourceforge.net/tracker/index.php?func=detail&aid=1432190&group_id=74338&atid=540672

I've commented in that bug report with links to the patch in the TurboGears tracker.

Comment 4 Luke Macken 2006-09-12 02:51:01 UTC
I applied this patch for FC5 and FC6.