New submission from Vince Spicer <vinces1...@gmail.com>:

eagerload throws an error when using eagerload against a dynamic relationship  

AttributeError: 'list' object has no attribute 'append_without_event'

So this fix looks for the lazy='dynamic' property and using lazyload in place 
of 
eagerlaod.

----------
files: adapters.diff
messages: 422
nosy: vinces1979
priority: bug
status: unread
title: [PATCH] repoze.what.plugins.sql  allow dynamic relationship
topic: repoze.what

__________________________________
Repoze Bugs <b...@bugs.repoze.org>
<http://bugs.repoze.org/issue154>
__________________________________
Index: repoze/what/plugins/sql/adapters.py
===================================================================
--- repoze/what/plugins/sql/adapters.py	(revision 9728)
+++ repoze/what/plugins/sql/adapters.py	(working copy)
@@ -62,7 +62,7 @@
 
 from sqlalchemy.exceptions import SQLAlchemyError
 from sqlalchemy.orm.exc import NoResultFound
-from sqlalchemy.orm import eagerload
+from sqlalchemy.orm import eagerload, lazyload
 
 from repoze.what.adapters import BaseSourceAdapter, SourceError
 
@@ -194,7 +194,12 @@
         # "field" usually equals to {tg_package}.model.User.user_name
         # or {tg_package}.model.Group.group_name
         field = getattr(self.children_class, self.translations['item_name'])
-        query = self.dbsession.query(self.children_class).options(eagerload(self.translations['sections']))
+        relation = getattr(self.children_class, self.translations['sections'])
+        if relation.property.lazy == 'dynamic':
+            joinload = lazyload(relation)
+        else:
+            joinload = eagerlaod(relation)
+        query = self.dbsession.query(self.children_class).options(joinload)
         try:
             item_as_row = query.filter(field==item_name).one()
         except NoResultFound:
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to