Hello there,
When I try to modify/update a primary key attribute in an inheritance
case, I always get a ConcurrentModificationError. Below is a
demonstration of the scenario based on the hierarchies paragraph from
the sqlalchemy documentation.
Can someone help me to get this right?
Many thanks in advance,
Marble
base = declarative_base()
class Employee(base):
employee_id = Column('employee_id', Integer, primary_key=True,
autoincrement=True)
name = Column('name', String(50),primary_key=True)
type = Column('type', String(30), nullable=False)
__tablename__ = 'employees'
__table_args__ = {'mysql_engine':'InnoDB'}
__mapper_args__ = {'polymorphic_on':type,
'polymorphic_identity':'employee'}
def __init__(self, name):
self.name = name
def __repr__(self):
return self.__class__.__name__ + " " + self.name
class Engineer(Employee):
employee_id = Column('employee_id', Integer, unique=True)
name = Column('name', String(50),primary_key=True)
engineer_info = Column('engineer_info', String(50), primary_key
=True)
__tablename__ = 'engineers'
__table_args__ = (ForeignKeyConstraint(['employee_id', 'name'],
['employees.employee_id',
'employees.name'],
onupdate="CASCADE",
ondelete="CASCADE"),
{'mysql_engine':'InnoDB'})
__mapper_args__ = {'inherits':Employee,
'inherit_condition': Employee.employee_id ==
employee_id,
'polymorphic_identity':'engineer'}
def __init__(self, name, engineer_info):
self.name = name
self.engineer_info = engineer_info
def __repr__(self):
return self.__class__.__name__ + " " + self.name + " " +
self.engineer_info
#=====================================================================
joe = Engineer('Joe','Engineer of the month')
session.add(joe)
session.commit()
joe.name = 'Joey' #Here I redefine the primary key
session.commit() #Now the Error is raised
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---