Joined table Inheritance attributes broken in 5.1

Issue #1292 resolved
Former user created an issue

I just upgraded from 5.0 to 5.1. The test below ran on 5.0 (and previous versions), but not on 5.1. I'm running on Windows with Python 2.6 (I haven't tried other OS's or Python versions yet). Below is cut and paste of a complete working test case using sqlite://.

#!/usr/bin/env python #$Id:simple_inheritance_test.py 16221 2008-10-01 18:05:20Z ken $ """ A simple test to show the base polymorphic identity is used """

import unittest from sqlalchemy import * from sqlalchemy.orm import *

class SimpleInheritanceTest1(unittest.TestCase): """ Shows polymorphic identity """

def test_poly_identity(self):
    """ Test polymorphic identity """
    metadata = MetaData('sqlite://')
    sess = create_session()

    class Base(object):
        """ Simple base class """
        id = None
        node_type = None
        name = None

        def __init__(self, name):
            self.name = name

    class Derived(Base):
        """ Simple derived class """
        pass

    def print_object(obj):
        """ Print some fields from the class """
        print **__name__: %s, name: %s id: %s, node_type: %s
        ** % ( obj.__class__.__name__, obj.name, obj.id, obj.node_type )

    base_table = Table( 'base_tbl',
                        metadata,
                        Column('id', Integer, primary_key = True),
                        Column('name', String(50)),
                        Column('node_type', String(50), nullable = False)
                        )

    derived_table = Table( 'derived_tbl',
                           metadata,
                           Column( 'id', None, ForeignKey('base_tbl.id'),
                                   primary_key = True))

    metadata.create_all()

    mapper(Base, base_table, polymorphic_on=base_table.c.node_type, 
           polymorphic_identity = 'Base')

    base1 = Base("base1")

    mapper(Derived, derived_table, inherits=Base,
           polymorphic_identity = 'Derived')

    derived2 = Derived("derived2")

    sess.add(base1)
    sess.add(derived2)

    sess.flush()
    print_object(base1)
    print_object(derived2)      # Prints node_type = Derived

    print "Done"

if name == "main": unittest.main()


Here's the output of the test.

ERROR: Test polymorphic identity

Traceback (most recent call last): File "M:\Workspace\py\pymb\db\test\simple_inheritance_test1.py", line 60, in test_poly_identity derived2 = Derived("derived2") File "<string>", line 4, in init File "c:\python26\lib\site-packages\sqlalchemy-0.5.1-py2.6.egg\sqlalchemy\orm\attributes.py", line 880, in initialize_instance return manager.events.original_init(mixed1:, *kwargs) File "<string>", line 6, in init File "M:\Workspace\py\pymb\db\test\simple_inheritance_test1.py", line 27, in init self.name = name File "c:\python26\lib\site-packages\sqlalchemy-0.5.1-py2.6.egg\sqlalchemy\orm\attributes.py", line 151, in set self.impl.set(instance_state(instance), value, None) AttributeError: 'NoneType' object has no attribute 'set'


Ran 1 test in 0.031s

FAILED (errors=1)

Comments (2)

  1. Log in to comment