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

Opened 13 years ago

Last modified 12 years ago

tg-admin sql drop fails with postgresql

Reported by: arthur@… Owned by: anonymous
Priority: normal Milestone: 0.9
Component: SQLObject Version: 0.9a6
Severity: normal Keywords:
Cc:

Description

When a model needs an order defined for creation, tg-admin sql drop doesn't do the right thing:

Model.py:

from sqlobject import *

soClasses = ('Source','Content')

class Source(SQLObject):
    name = UnicodeCol()
    contents = MultipleJoin('Content')

class Content(SQLObject):
    body = UnicodeCol()
    source = ForeignKey('Source')
kremer:testing $ tg-admin sql create
Using database URI postgres://db:passwd@localhost/testing
kremer:testing $ tg-admin sql drop  
Using database URI postgres://db:passwd@localhost/testing
Traceback (most recent call last):
  File "/usr/local/bin/tg-admin", line 7, in ?
    sys.exit(
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/command/base.py", line 275, in main
    command.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/TurboGears-0.9a6-py2.4.egg/turbogears/command/base.py", line 134, in run
    command.the_runner.run(sys.argv)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/manager/command.py", line 102, in run
    runner.run()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/manager/command.py", line 233, in run
    self.command()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/manager/command.py", line 604, in command
    soClass.dropTable()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/main.py", line 1311, in dropTable
    conn.dropTable(cls.sqlmeta.table, cascade)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/postgres/pgconnection.py", line 157, in dropTable
    self.query("DROP TABLE %s %s" % (tableName,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/dbconnection.py", line 305, in query
    return self._runWithConnection(self._query, s)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/dbconnection.py", line 219, in _runWithConnection
    val = meth(conn, *args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/dbconnection.py", line 302, in _query
    self._executeRetry(conn, conn.cursor(), s)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1675-py2.4.egg/sqlobject/dbconnection.py", line 297, in _executeRetry
    return cursor.execute(query)
psycopg.ProgrammingError: ERROR:  cannot drop table source because other objects depend on it
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

DROP TABLE source

tg-admin sql drop should drop objects in the opposite order to creation.

(postgres8, OS X 10.4)

Attachments

command.patch Download (113 bytes) - added by jorge.vargas 13 years ago.
I think this simple fix could do it this is NOT tested

Change History

Changed 13 years ago by jorge.vargas

I think this simple fix could do it this is NOT tested

comment:1 Changed 13 years ago by jorge.vargas

  • Component changed from TurboGears to SQLObject
  • Milestone set to 0.9

this must be fix at SQLObject, could you make a bug there pointing here.

I have track down the issue to  http://svn.colorstudy.com/SQLObject/branches/0.7-bugfix/sqlobject/manager/command.py

I believe something as simple as iterating the classes backward could fix this. see command.patch

I'm not sure if adding a cascade will be a good idea since this is use for other things . and people may not want that. Maybe a flag?

comment:2 Changed 13 years ago by arthur@…

Reported to SQLOBject bug tracker as bug ID 1495030

comment:3 Changed 13 years ago by yemartin

The patch proposed by jorge.vargas is now included in a tentative patch that tries to fix the root of the issue in #279. See patch file there.

comment:4 Changed 13 years ago by jorge.vargas

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

closing this go to #279 for follow up

Note: See TracTickets for help on using tickets.