Ticket #882 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

tg-admin sql drop fails with postgresql

Reported by: arthur@clune.org Assigned to: 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 (113 bytes) - added by jorge.vargas on 05/25/06 10:30:13.
I think this simple fix could do it this is NOT tested

Change History

05/25/06 10:30:13 changed by jorge.vargas

  • attachment command.patch added.

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

05/25/06 10:31:13 changed 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?

05/25/06 11:01:47 changed by arthur@clune.org

Reported to SQLOBject bug tracker as bug ID 1495030

08/08/06 20:24:45 changed 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.

08/25/06 23:02:52 changed by jorge.vargas

  • status changed from new to closed.
  • resolution set to fixed.

closing this go to #279 for follow up