diff options
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r-- | mediagoblin/db/models.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 6448de36..f4644b9f 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -998,10 +998,17 @@ class Comment(Base): return self.comment().get_actor # noqa def __getattr__(self, attr): + if attr.startswith('_'): + # if attr starts with '_', then it's probably some internal + # sqlalchemy variable. Since __getattr__ is called when + # non-existing attributes are being accessed, we should not try to + # fetch it from self.comment() + raise AttributeError try: + _log.debug('Old attr is being accessed: {0}'.format(attr)) return getattr(self.comment(), attr) # noqa except Exception as e: - print(e) + _log.error(e) raise class TextComment(Base, TextCommentMixin, CommentingMixin): @@ -1155,11 +1162,11 @@ class Collection(Base, CollectionMixin, CommentingMixin): def get_collection_items(self, ascending=False): #TODO, is this still needed with self.collection_items being available? - order_col = MediaEntry.created + order_col = CollectionItem.position if not ascending: order_col = desc(order_col) - return CollectionItem.query.join(MediaEntry).filter( - CollectionItem.collection==self.id).order_by(order_col) + return CollectionItem.query.filter_by( + collection=self.id).order_by(order_col) def __repr__(self): safe_title = self.title.encode('ascii', 'replace') |