I'm getting an error like this: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/pyramid_debugtoolbar/panels/performance.py", line 57, in resource_timer_handler result = handler(request) File "/app/warehouse/raven.py", line 41, in raven_tween return handler(request) File "/usr/local/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 171, in tm_tween reraise(*exc_info) File "/usr/local/lib/python3.6/site-packages/pyramid_tm/compat.py", line 36, in reraise raise value File "/usr/local/lib/python3.6/site-packages/pyramid_tm/__init__.py", line 136, in tm_tween response = handler(request) File "/usr/local/lib/python3.6/site-packages/pyramid/tweens.py", line 41, in excview_tween response = _error_handler(request, exc) File "/usr/local/lib/python3.6/site-packages/pyramid/tweens.py", line 16, in _error_handler reraise(*exc_info) File "/usr/local/lib/python3.6/site-packages/pyramid/compat.py", line 148, in reraise raise value File "/usr/local/lib/python3.6/site-packages/pyramid/tweens.py", line 39, in excview_tween response = handler(request) File "/app/warehouse/cache/http.py", line 69, in conditional_http_tween response = handler(request) File "/usr/local/lib/python3.6/site-packages/pyramid/router.py", line 156, in handle_request view_name File "/usr/local/lib/python3.6/site-packages/pyramid/view.py", line 617, in _call_view response = view_callable(context, request) File "/app/warehouse/sessions.py", line 293, in wrapped return view(context, request) File "/app/warehouse/csrf.py", line 38, in wrapped return view(context, request) File "/usr/local/lib/python3.6/site-packages/pyramid/viewderivers.py", line 512, in csrf_view return view(context, request) File "/app/warehouse/cache/http.py", line 43, in wrapped response = view(context, request) File "/app/warehouse/cache/origin/__init__.py", line 81, in wrapped return view(context, request) File "/usr/local/lib/python3.6/site-packages/pyramid/viewderivers.py", line 461, in rendered_view request, result, view_inst, context) File "/usr/local/lib/python3.6/site-packages/pyramid/renderers.py", line 435, in render_view return self.render_to_response(response, system, request=request) File "/usr/local/lib/python3.6/site-packages/pyramid/renderers.py", line 458, in render_to_response result = self.render(value, system_values, request=request) File "/usr/local/lib/python3.6/site-packages/pyramid/renderers.py", line 454, in render result = renderer(value, system_values) File "/usr/local/lib/python3.6/site-packages/pyramid/renderers.py", line 277, in _render return self.serializer(value, default=default, **self.kw) File "/usr/local/lib/python3.6/json/__init__.py", line 238, in dumps **kw).encode(obj) File "/usr/local/lib/python3.6/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/local/lib/python3.6/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/usr/local/lib/python3.6/site-packages/pyramid/renderers.py", line 290, in default raise TypeError('%r is not JSON serializable' % (obj,)) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 708, in __repr__ return repr(list(self)) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 512, in __len__ return len(self.col) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 509, in <lambda> col = property(lambda self: self.lazy_collection()) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/associationproxy.py", line 465, in __call__ "stale association proxy, parent object has gone out of " sqlalchemy.exc.InvalidRequestError: stale association proxy, parent object has gone out of scope
However, for the life of me I can't seem to figure out *why*. It's hard to find much information about this error online, but what I can find suggests something is going out of scope and getting garbage collected. I can't figure out what that thing would be though. For reference, the model I'm using is https://github.com/pypa/warehouse/blob/dbb965a354835b383a30a94177ef8231e9d3532b/warehouse/packaging/models.py#L212-L353 and I'm using it in this view https://github.com/pypa/warehouse/blob/dbb965a354835b383a30a94177ef8231e9d3532b/warehouse/legacy/api/json.py#L57-L176. As it is that view works, but if I attempt to access Release.requires_dist, then it blows up with the above error, with a diff like: diff --git a/warehouse/legacy/api/json.py b/warehouse/legacy/api/json.py index edf0283..da03d86 100644 --- a/warehouse/legacy/api/json.py +++ b/warehouse/legacy/api/json.py @@ -166,6 +166,7 @@ def json_release(release, request): name=project.name, version=release.version, ), + "requires_dist": release.requires_dist, "docs_url": project.documentation_url, "bugtrack_url": project.bugtrack_url, "home_page": release.home_page, If I instead use release._requires_dist, then it works fine (other than the JSON seriaization fails, because it's a ORM object that can't be serialized). What am I doing wrong here? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.