Skip to content

Instantly share code, notes, and snippets.

@jasonamyers
Last active December 11, 2015 05:59
Show Gist options
  • Save jasonamyers/4556201 to your computer and use it in GitHub Desktop.
Save jasonamyers/4556201 to your computer and use it in GitHub Desktop.
Wierd SQL Alchemy Error
def catalogs_home(request):
userid = authenticated_userid(request)
username = Users.by_id(userid).username
clients = DBSession.query(Clients).order_by(Clients.active).all()
commodities_count = []
sandbox_status = []
production_status = []
for client in clients:
category_count = 0
for category in client.categories:
category_count += DBSession.query(Commodities).filter(Commodities.category_id == category.category_id).co
commodities_count.append(category_count)
sandbox_cat, sandbox_com = verify_catalog_publishing(client.client_id, False)
if not sandbox_cat.find('COMPLETE') and not sandbox_com.find('COMPLETE'):
sandbox_status.append('In Progress')
production_cat, production_com = verify_catalog_publishing(client.client_id, True)
if not production_cat.find('COMPLETE') and not production_com.find('COMPLETE'):
production_status.append('In Progress')
DetachedInstanceError: Parent instance <Clients at 0x108317f10> is not bound to a Session; lazy load operation of attribute 'categories' cannot proceed
If I comment out lines 14-19 below I do not get the error.
Traceback (most recent call last):
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.4-py2.7.egg/pyramid_debugtoolbar/panels/performance.py", line 55, in resource_timer_handler
result = handler(request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
response = handler(request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 82, in tm_tween
reraise(*exc_info)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 63, in tm_tween
response = handler(request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid/router.py", line 161, in handle_request
response = view_callable(context, request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid/config/views.py", line 237, in _secured_view
return view(context, request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid/config/views.py", line 345, in rendered_view
result = view(context, request)
File "/Users/jasonamyers/.virtualenv/cornerstone/lib/python2.7/site-packages/pyramid/config/views.py", line 491, in _requestonly_view
response = view(request)
File "/Users/jasonamyers/projects/cornerstone/cornerstone/views/catalogs.py", line 35, in catalogs_home
for category in client.categories:
File "build/bdist.macosx-10.8-x86_64/egg/sqlalchemy/orm/attributes.py", line 251, in __get__
return self.impl.get(instance_state(instance), dict_)
File "build/bdist.macosx-10.8-x86_64/egg/sqlalchemy/orm/attributes.py", line 545, in get
value = self.callable_(state, passive)
File "build/bdist.macosx-10.8-x86_64/egg/sqlalchemy/orm/strategies.py", line 497, in _load_for_state
(orm_util.state_str(state), self.key)
DetachedInstanceError: Parent instance <Clients at 0x108317f10> is not bound to a Session; lazy load operation of attribute 'categories' cannot proceed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment