On 11/15/2015 06:44 PM, Fabian Freyer wrote:
> Hi,
> 
> I am trying to do some ugly schemaception. A semi-working minimal
> example is at
> https://gist.github.com/fabianfreyer/f92054d260dc0485c649#file-field_storage-py.
> 
> The data model I am implementing is hierarchical, fieldable containers.
> Field types are created by sub-classing Schema instances. This part works.
> I am having problems implementing a way of grouping those fields by
> their Category. For this purpose I have added a collection_class (see
> lines 50-) that should take care of the grouping and be interfaceable as
> a 2D dictionary as in
> 
>     field = container.categories[category.name][field.name]
> 
> This works on the first access. On the second access it throws a
> DetachedInstanceError (see
> https://gist.github.com/fabianfreyer/f92054d260dc0485c649#file-traceback1)
> 
> To mitigate this I have added lines 63 to 65 (commented out in the
> gist). When these are uncommented, there is also a DetachedInstanceError
> (see
> https://gist.github.com/fabianfreyer/f92054d260dc0485c649#file-traceback2)
> 
> I am running this in flask by the way.
> 
> What's the preferred way to deal with this? Am I on the completely wrong
> track to group a collection?


the first traceback illustrates a jinja template attempting to access
the unloaded attributes of a Field object, however the Field is not
associated with a session so these can't load.  Similarly, the second
traceback ilustrates a query that is querying on the ".id" element of a
mapped object of some kind, however this attribute is unloaded and again
the object is not attached to a Session so cannot be loaded.

Both issues involve attempting to work with detached objects that have
also been expired (note that expiration occurs automatically when a
Session object is committed unless it is configured not to do this).
The models illustrated are not relevant to this issue.


> 
> Fabian Freyer
> 

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to