From 3fe47e666f9db09be9b1eab4a11620e8ea71ea65 Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Wed, 8 Mar 2017 18:41:02 +0100 Subject: [PATCH] Fix polymorphism problem with relationships Since we are using subclasses of the ORM mapped classes, disable typechecks for ORM relations --- lib/mysqlred.py | 8 +++++--- lib/redpage.py | 9 +-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/mysqlred.py b/lib/mysqlred.py index 232dc7c..4f6101e 100644 --- a/lib/mysqlred.py +++ b/lib/mysqlred.py @@ -249,7 +249,8 @@ class MysqlRedFam( Mysql, Base ): __article3_status, __article4_status, __article5_status, __article6_status, __article7_status ) - redpage = relationship( "MysqlRedPage", back_populates="redfams" ) + redpage = relationship( "MysqlRedPage", enable_typechecks=False, + back_populates="redfams" ) @property def articlesList(self): @@ -299,8 +300,9 @@ class MysqlRedPage( Mysql, Base ): nullable=True ) redfams = relationship( - "MysqlRedFam", order_by=MysqlRedFam.famhash, back_populates="redpage", - collection_class=attribute_mapped_collection("famhash")) + "MysqlRedFam", enable_typechecks=False, + back_populates="redpage", order_by=MysqlRedFam.famhash, + collection_class=attribute_mapped_collection("famhash") ) @property def status( self ): diff --git a/lib/redpage.py b/lib/redpage.py index 3678111..69f02b8 100644 --- a/lib/redpage.py +++ b/lib/redpage.py @@ -30,8 +30,7 @@ import mwparserfromhell as mwparser import jogobot # noqa -from lib.mysqlred import MysqlRedPage, relationship -from sqlalchemy.orm.collections import attribute_mapped_collection +from lib.mysqlred import MysqlRedPage from lib.redfam import RedFamParser @@ -40,12 +39,6 @@ class RedPage( MysqlRedPage ): Class for handling redundance discussion pages and archives """ - # TODO POLYMORPHISM? of BASEClass - redfams = relationship( - "RedFamParser", order_by=RedFamParser.famhash, - back_populates="redpage", - collection_class=attribute_mapped_collection( "famhash" ) ) - def __init__( self, page=None, pageid=None, archive=False ): """ Generate a new RedPage object based on the given pywikibot page object