On Oct 28, 2011, at 7:09 PM, Burak Arslan wrote: > um, this doesn't crash at all here, are you sure you didn't miss something ? > i can do a "print B()"
Here is that test again, not using the __abstract__ keyword which was only
introduced in 0.7.3:
from sqlalchemy import Integer, Column
from sqlalchemy.ext.declarative import declarative_base
Base= declarative_base()
class A(Base):
__tablename__ = "a"
id = Column(Integer, primary_key=True)
class B(A):
pass
B.__mapper__.dispose()
B._sa_class_manager = A._sa_class_manager
B()
Next, here is rpclib's code causing this issue. rpclib attempts to make a
copy of the class, and appears to do only a shallow copy, so that both classes
share the same "_sa_class_state" registry:
from rpclib.model import ModelBase
from rpclib.model.complex import Array
from sqlalchemy import Table, Column, Integer, MetaData
from sqlalchemy.orm import mapper
class Patient(ModelBase):
pass
patient = Table('patient', MetaData(), Column('id', Integer, primary_key=True))
mapper(Patient, patient)
x = Array(Patient)
incorrectly_copied_Patient_cls = Array(Patient)._type_info['Patient']
good_patient = Patient()
bad_patient = incorrectly_copied_Patient_cls()
SQLAlchemy isn't currently compatible with this approach. The attached patch
modifies ClassManager to gracefully resolve a "shallow copy" of a class back to
the "original" class, but I don't know what further side effects or unexpected
behaviors might arise from that unless it were a fully tested use case. There
are ways to redefine how the "class manager" of a class is retrieved from a
class, which is part of some hooks we added some years back to support Trellis,
but that's getting into some murky areas. It would easier if rpclib didn't
need to copy classes, though.
allow_class_copies.patch
Description: Binary data
-- 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.
