Single table inheritence when a class is removed

19 views
Skip to first unread message

Chris Withers

unread,
Dec 29, 2009, 1:07:50 PM12/29/09
to sqlal...@googlegroups.com
Hi All,

We're using single table inheritence in one of our projects but we have
some obsolete rows that are each mapped to their own python class.

If we remove the obsolete classes, when we try and do:

session.query(TheBaseClass)

...we get:

File
"/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.5-py2.5.egg/sqlalchemy/orm/mapper.py",
line 1742, in configure_subclass_mapper
raise AssertionError("No such polymorphic_identity %r is defined" %
discriminator)
AssertionError: No such polymorphic_identity 'TheClassName' is defined

Is there any way to phrase that query as "just ignore rows where no
polymorphic mapper can be found"?

If not, I guess I need to do session.query(TheClassName).delete() before
I remove the code, right?

cheers,

Chris

Michael Bayer

unread,
Dec 29, 2009, 1:25:50 PM12/29/09
to sqlal...@googlegroups.com

it would be best to remove the rows. Otherwise, you'd need to filter()
your queries on "TheBaseClass.type != 'TheClassName'" to prevent those
rows from coming in.

This is a common problem we have all the time here.

Chris Withers

unread,
Dec 29, 2009, 5:28:40 PM12/29/09
to sqlal...@googlegroups.com
Michael Bayer wrote:
> it would be best to remove the rows. Otherwise, you'd need to filter()
> your queries on "TheBaseClass.type != 'TheClassName'" to prevent those
> rows from coming in.
>
> This is a common problem we have all the time here.

If that's so, could a flag not be added somewhere (waves hands idly) in
the process that said "ignore or emit warnings for rows with no matching
class"?

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

Reply all
Reply to author
Forward
0 new messages