#73 Bug in handling of non default foreign key values

closed-fixed
None
5
2006-10-31
2006-10-12
Anonymous
No

se:

http://trac.turbogears.org/turbogears/ticket/1139

for bug description and patch.

Thanks,

Tormod Ravnanger Landet

Discussion

  • Tormod Ravnanger Landet

    Logged In: YES
    user_id=1631055

    Adding testcase

     
  • Tormod Ravnanger Landet

    Logged In: YES
    user_id=1631055

    Seems there is a problem adding files

    Testcase to show the bug:

    from sqlobject import *
    from sqlobject.inheritance import InheritableSQLObject

    class Base(InheritableSQLObject):
    pass

    class File(SQLObject):
    pass

    class MyClass(Base):
    aFile = ForeignKey("Base")
    otherFile = ForeignKey("Base", default=None)

    sqlhub.processConnection = connectionForURI('sqlite:/:memory:')

    Base.createTable()
    File.createTable()
    MyClass.createTable()

    file1 = File()
    file2 = File()

    print MyClass.sqlmeta.columnList
    # [<SOStringCol childName default=None>, <SOForeignKey
    aFileID connected to Base>, <SOForeignKey otherFileID
    default=None connected to Base>]

    object = MyClass(aFile=file1, otherFile=file2)

    # Traceback (most recent call last):
    # File "/home/landet/work/eclipseworkspace/Diverse
    Pythonscript/src/SQLObject_bugfixing/case.py", line 23, in ?
    # object = MyClass(aFile=file1, otherFile=file2)
    # File
    "/home/landet/lib/python-2.4/SQLObject-0.7.1-py2.4.egg/sqlobject/declarative.py",
    line 93, in _wrapper
    # return fn(self, *args, **kwargs)
    # File
    "/home/landet/lib/python-2.4/SQLObject-0.7.1-py2.4.egg/sqlobject/main.py",
    line 1198, in __init__
    # self._create(id, **kw)
    # File
    "/home/landet/lib/python-2.4/SQLObject-0.7.1-py2.4.egg/sqlobject/inheritance/__init__.py",
    line 219, in _create
    # raise TypeError, "%s() did not get expected keyword
    argument %s" % (self.__class__.__name__, col.name)
    # TypeError: MyClass() did not get expected keyword argument
    aFileID

     
  • Tormod Ravnanger Landet

    Logged In: YES
    user_id=1631055

    Fix:

    change the file sqlobject.inheritance.init line 218

    from:

    if col._default == sqlbuilder.NoDefault and col.name not in kw:

    to:

    if col._default == sqlbuilder.NoDefault and col.name not in
    kw and (col.foreignName is None or col.foreignName not in kw):

     
  • Oleg Broytman

    Oleg Broytman - 2006-10-31
    • assigned_to: nobody --> phd
    • status: open --> open-fixed
     
  • Oleg Broytman

    Oleg Broytman - 2006-10-31
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.