Hello again dear list,

I have a mapped class is polymorphic with single table inheritance. I have
a function wired up to the load() SA event. The dictionary in the
InstanceState which is passed to the load event depends on whether I am
querying on the base class or a derived one, which I don't _think_ it
should be.

Here is a concrete example, which is a bit contrived - I am actually knee
deep inside mapping mutable JSON objects stored in values of HSTOREs; this
is a distilled version of the problem:

class PolyBase(Base):
    name            = Column(String, primary_key=True)
    type            = Column(String)
    __mapper_args__ = {'polymorphic_on': type}

class Cake(PolyBase):
    topping         = Column(String)
    __mapper_args__ = {'polymorphic_identity': 'Cake'}

def load_event(state, *args):
    print state.dict.keys()

sqlalchemy.event.listen(Cake, 'load', load_event, raw=True, propagate=True)

Now:

> session().query(Cake).filter_by(name='mycake').one()
['date', '_sa_instance_state', 'type', 'name']

However, in a fresh session:

> session().query(PolyBase).filter_by(name='mycake').one()
['_sa_instance_state', 'type', 'name']

See 'date' is missing when I query on PolyBase, even though in both cases
state.obj is a Cake instance. I've been looking at the object loading code
in SQLAlchemy and it is rather fierce; is this expected behavior?

Either way can anyone think of a fix/workaround?

Cheers for reading this far!

- Philip

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to