I'm new to both python and SQLAlchemy, but am improving.  I'm building
a new application that will use a sqlite database.  A unit test is
failing with this exception:
"sqlalchemy.exceptions.ConcurrentModificationError: Updated rowcount 0
does not match number of objects updated 1"

Below is a small version of what I'm trying to do.  Is this a
SQLAlchemy bug or do I need to be doing something differently?  The
error happens on the final flush() call.
####################################
import sqlalchemy as sqla

db_con = sqla.create_engine('sqlite:///:memory:')
metadata = sqla.BoundMetaData(db_con)

signal_types = sqla.Table('signal_types', metadata,
        sqla.Column('signal_type_id',
                    sqla.Integer,
                    primary_key = True),
        sqla.Column('signal_type_name',
                    sqla.String(25),
                    nullable = False,
                    unique = True),
        sqla.UniqueConstraint('signal_type_name',
                              name = 'signal_types_idx1')
        )

signal_enumerations = sqla.Table('signal_enumerations', metadata,
        sqla.Column('signal_type_id',
                    sqla.Integer,
                    sqla.ForeignKey('signal_types.signal_type_id'),
                    nullable = False),
        sqla.Column('signal_enumeration_name',
                    sqla.String(50),
                    nullable = False),
        sqla.Column('signal_enumeration_value',
                    sqla.Integer,
                    nullable = False),
        sqla.PrimaryKeyConstraint('signal_type_id', 'signal_enumeration_name')
        )

metadata.create_all()
session = sqla.create_session(db_con)


class Signal_type(object):
    "Model class for the Signal_types table"

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


class Signal_enumeration(object):
    "Model class for the Signal_enumeration table"

    def __init__(self, name, value):
        self.signal_enumeration_name = name
        self.signal_enumeration_value = value

    def __repr__(self):
        return "%s: %d" % (self.signal_enumeration_name,
                self.signal_enumeration_value)

# Table signal_types
#   Primary Key: signal_type_id
signal_types_mapper = sqla.mapper(Signal_type, signal_types)


# Table signal_enumerations
#   Primary Key: signal_enumeration_name
#   Foreign Key: signal_types(signal_type_id)
sqla.mapper(Signal_enumeration, signal_enumerations)

signal_types_mapper.add_property('enumerations',
        sqla.relation(Signal_enumeration,
        order_by = signal_enumerations.c.signal_enumeration_value,
        cascade = "all, delete-orphan"))

###########################################################################
# Add database data
new_type = Signal_type('enum_type')

new_type.enumerations.append(Signal_enumeration('one', 1))
new_type.enumerations.append(Signal_enumeration('two', 2))
new_type.enumerations.append(Signal_enumeration('three', 3))
new_type.enumerations.append(Signal_enumeration('four', 4))

session.save(new_type)
session.flush()

new_type.enumerations[2].signal_enumeration_name = 'thirty'
#session.flush()
new_type.enumerations[2].signal_enumeration_value = 30

session.flush()

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to