python - Can SQLAlchemy handle unknown polymorphic identities? -


i have 2 parts of app: ingestion , display. ideally, both of these @ same version of code, alas, reality doesn't allow simultaneous deployments. also, it's useful work on data ingestion before rolling out corresponding frontend.

the problem have i'm using sqlalchemy's polymorphic identities, , when add new class on backend, frontend doesn't know it. here's specific example. have code:

class campaign(basedata):     __tablename__ = 'campaign'     __mapper_args__ = {         'polymorphic_identity': 'parent',         'polymorphic_on': description     }  class subcampaign(campaign):     __mapper_args__ = {         'polymorphic_identity': 'sub'     } 

then, add new class:

class othercampaign(campaign):     __mapper_args__ = {         'polymorphic_identity': 'other'     } 

when insert rows db description column set other, throw error:

no such polymorphic_identity 'other' defined 

is there way work around this? i'd happy ignore rows.

based on discussion zzzeek in comments, ended changing query on read side request valid data. instead of:

rows =  session.query(campaign).all() 

i'm doing

valid_descriptions = [m.polymorphic_identity m in                        campaign.__mapper__.polymorphic_iterator()] rows =  session.query(campaign)\                 .filter(campaign.description.in_(valid_descriptions))\                 .all() 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -