ome / omero-blitz

Gradle project containing Ice remoting code for OMERO
https://www.openmicroscopy.org/omero
GNU General Public License v2.0
0 stars 15 forks source link

getShapeStatsRestricted - bug for ROIs with linked annotations #144

Open emilroz opened 1 year ago

emilroz commented 1 year ago

While debugging Batch ROI Export.py OMERO.script Glencoe has come across the issue with getShapeStatsRestricted call which appears to only work for the Shapes that do not have any annotations. While model allows to link annotations to Shapes there's probably a small number of OMERO.clients that use this functionality, however PathViewer uses it extensively to store additional information about user preferences, etc. which currently makes this call\OMERO.script non functional for any ROIs created with PathViewer or any other client that links annotations to Shapes.

Exception details:

WARNING:omero.gateway:InternalException on <class 'omero.gateway.OmeroGatewaySafeCallWrapper'> to <088f5f3f-dbe3-467f-bb56-ef5e69112069omero.api.IRoi> getShapeStatsRestricted(([4651], 0, 0, [0]), {})
Traceback (most recent call last):
  File "/opt/omero/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py", line 4856, in __call__
    return self.f(*args, **kwargs)
  File "/opt/omero/OMERO.venv/lib/python3.10/site-packages/omero_api_IRoi_ice.py", line 826, in getShapeStatsRestricted
    return _M_omero.api.IRoi._op_getShapeStatsRestricted.invoke(self, ((shapeIdList, zForUnattached, tForUnattached, channels), _ctx))
omero.InternalException: exception ::omero::InternalException
{
    serverStackTrace = ome.conditions.InternalException:  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:709)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:416)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:125)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.tools.hibernate.ProxyCleanupFilter$Interceptor.invoke(ProxyCleanupFilter.java:249)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy81.doWork(Unknown Source)
    at ome.services.util.Executor$Impl.execute(Executor.java:447)
    at ome.services.util.Executor$Impl.execute(Executor.java:392)
    at ome.services.throttling.Adapter.run(Adapter.java:50)
    at ome.services.throttling.InThreadThrottlingStrategy.runnableCall(InThreadThrottlingStrategy.java:89)
    at ome.services.blitz.impl.AbstractAmdServant.runnableCall(AbstractAmdServant.java:154)
    at ome.services.blitz.impl.RoiI.getShapeStatsRestricted_async(RoiI.java:252)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at omero.cmd.CallContext.invoke(CallContext.java:85)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy111.getShapeStatsRestricted_async(Unknown Source)
    at omero.api._IRoiTie.getShapeStatsRestricted_async(_IRoiTie.java:148)
    at omero.api._IRoiDisp.___getShapeStatsRestricted(_IRoiDisp.java:436)
    at omero.api._IRoiDisp.__dispatch(_IRoiDisp.java:657)
    at IceInternal.Incoming.invoke(Incoming.java:221)
    at Ice.ConnectionI.invokeAll(ConnectionI.java:2536)
    at Ice.ConnectionI.dispatch(ConnectionI.java:1145)
    at Ice.ConnectionI.message(ConnectionI.java:1056)
    at IceInternal.ThreadPool.run(ThreadPool.java:395)
    at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
    at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
    at java.base/java.lang.Thread.run(Thread.java:829)

    serverExceptionClass = ome.conditions.InternalException
    message =  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
}
---------------------------------------------------------------------------
InternalException                         Traceback (most recent call last)
Cell In[32], line 1
----> 1 stats2 = roi_service.getShapeStatsRestricted([shape.id.val], 0, 0, [0])

File ~/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py:4859, in OmeroGatewaySafeCallWrapper.__call__(self, *args, **kwargs)
   4857 except Exception as e:
   4858     self.debug(e.__class__.__name__, args, kwargs)
-> 4859     return self.handle_exception(e, *args, **kwargs)

File ~/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py:4856, in OmeroGatewaySafeCallWrapper.__call__(self, *args, **kwargs)
   4854 def __call__(self, *args, **kwargs):
   4855     try:
-> 4856         return self.f(*args, **kwargs)
   4857     except Exception as e:
   4858         self.debug(e.__class__.__name__, args, kwargs)

File ~/OMERO.venv/lib/python3.10/site-packages/omero_api_IRoi_ice.py:826, in IRoiPrx.getShapeStatsRestricted(self, shapeIdList, zForUnattached, tForUnattached, channels, _ctx)
    825 def getShapeStatsRestricted(self, shapeIdList, zForUnattached, tForUnattached, channels, _ctx=None):
--> 826     return _M_omero.api.IRoi._op_getShapeStatsRestricted.invoke(self, ((shapeIdList, zForUnattached, tForUnattached, channels), _ctx))

InternalException: exception ::omero::InternalException
{
    serverStackTrace = ome.conditions.InternalException:  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:709)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:416)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:125)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.tools.hibernate.ProxyCleanupFilter$Interceptor.invoke(ProxyCleanupFilter.java:249)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy81.doWork(Unknown Source)
    at ome.services.util.Executor$Impl.execute(Executor.java:447)
    at ome.services.util.Executor$Impl.execute(Executor.java:392)
    at ome.services.throttling.Adapter.run(Adapter.java:50)
    at ome.services.throttling.InThreadThrottlingStrategy.runnableCall(InThreadThrottlingStrategy.java:89)
    at ome.services.blitz.impl.AbstractAmdServant.runnableCall(AbstractAmdServant.java:154)
    at ome.services.blitz.impl.RoiI.getShapeStatsRestricted_async(RoiI.java:252)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at omero.cmd.CallContext.invoke(CallContext.java:85)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy111.getShapeStatsRestricted_async(Unknown Source)
    at omero.api._IRoiTie.getShapeStatsRestricted_async(_IRoiTie.java:148)
    at omero.api._IRoiDisp.___getShapeStatsRestricted(_IRoiDisp.java:436)
    at omero.api._IRoiDisp.__dispatch(_IRoiDisp.java:657)
    at IceInternal.Incoming.invoke(Incoming.java:221)
    at Ice.ConnectionI.invokeAll(ConnectionI.java:2536)
    at Ice.ConnectionI.dispatch(ConnectionI.java:1145)
    at Ice.ConnectionI.message(ConnectionI.java:1056)
    at IceInternal.ThreadPool.run(ThreadPool.java:395)
    at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
    at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
    at java.base/java.lang.Thread.run(Thread.java:829)

    serverExceptionClass = ome.conditions.InternalException
    message =  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
}

Minimal example to reproduce the issue:

from omero.gateway import BlitzGateway
from omero.rtypes import rdouble
import omero.clients

conn = BlitzGateway(<CONNECTION INFO>)
conn.connect()

image = conn.getObject("Image", <IMAGE ID>)
roi = omero.model.RoiI()
shape = omero.model.RectangleI()

shape.setX(rdouble(0))
shape.setY(rdouble(0))
shape.setWidth(rdouble(100))
shape.setHeight(rdouble(100))

roi.addShape(shape)
roi.setImage(image._obj)
us = conn.getUpdateService()
roi = us.saveAndReturnObject(roi)
shape = roi.copyShapes()[0]

roi_service = conn.getRoiService()
stats = roi_service.getShapeStatsRestricted([shape.id.val], 0, 0, [0])
print(stats)
"""
[object #0 (::omero::api::ShapeStats)
{
    shapeId = 4651
    channelIds = 
    {
        [0] = 0
    }
    pointsCount = 
    {
        [0] = 10000
    }
    min = 
    {
        [0] = 0.0
    }
    max = 
    {
        [0] = 255.0
    }
    sum = 
    {
        [0] = 993703.0
    }
    mean = 
    {
        [0] = 99.3703
    }
    stdDev = 
    {
        [0] = 89.19983542010544
    }
}]
"""

# Add annotation to the shape and repeat:
ann = omero.model.TermAnnotationI()
ann.setTermValue(omero.rtypes.rstring("Some value"))
shape.linkAnnotation(ann)
shape = us.saveAndReturnObject(shape)
shape.sizeOfAnnotationLinks()
"""
Out: 1
"""

stats2 = roi_service.getShapeStatsRestricted([shape.id.val], 0, 0, [0])
"""
WARNING:omero.gateway:InternalException on <class 'omero.gateway.OmeroGatewaySafeCallWrapper'> to <088f5f3f-dbe3-467f-bb56-ef5e69112069omero.api.IRoi> getShapeStatsRestricted(([4651], 0, 0, [0]), {})
Traceback (most recent call last):
  File "/opt/omero/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py", line 4856, in __call__
    return self.f(*args, **kwargs)
  File "/opt/omero/OMERO.venv/lib/python3.10/site-packages/omero_api_IRoi_ice.py", line 826, in getShapeStatsRestricted
    return _M_omero.api.IRoi._op_getShapeStatsRestricted.invoke(self, ((shapeIdList, zForUnattached, tForUnattached, channels), _ctx))
omero.InternalException: exception ::omero::InternalException
{
    serverStackTrace = ome.conditions.InternalException:  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:709)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:416)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:125)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.tools.hibernate.ProxyCleanupFilter$Interceptor.invoke(ProxyCleanupFilter.java:249)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy81.doWork(Unknown Source)
    at ome.services.util.Executor$Impl.execute(Executor.java:447)
    at ome.services.util.Executor$Impl.execute(Executor.java:392)
    at ome.services.throttling.Adapter.run(Adapter.java:50)
    at ome.services.throttling.InThreadThrottlingStrategy.runnableCall(InThreadThrottlingStrategy.java:89)
    at ome.services.blitz.impl.AbstractAmdServant.runnableCall(AbstractAmdServant.java:154)
    at ome.services.blitz.impl.RoiI.getShapeStatsRestricted_async(RoiI.java:252)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at omero.cmd.CallContext.invoke(CallContext.java:85)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy111.getShapeStatsRestricted_async(Unknown Source)
    at omero.api._IRoiTie.getShapeStatsRestricted_async(_IRoiTie.java:148)
    at omero.api._IRoiDisp.___getShapeStatsRestricted(_IRoiDisp.java:436)
    at omero.api._IRoiDisp.__dispatch(_IRoiDisp.java:657)
    at IceInternal.Incoming.invoke(Incoming.java:221)
    at Ice.ConnectionI.invokeAll(ConnectionI.java:2536)
    at Ice.ConnectionI.dispatch(ConnectionI.java:1145)
    at Ice.ConnectionI.message(ConnectionI.java:1056)
    at IceInternal.ThreadPool.run(ThreadPool.java:395)
    at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
    at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
    at java.base/java.lang.Thread.run(Thread.java:829)

    serverExceptionClass = ome.conditions.InternalException
    message =  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
}
---------------------------------------------------------------------------
InternalException                         Traceback (most recent call last)
Cell In[32], line 1
----> 1 stats2 = roi_service.getShapeStatsRestricted([shape.id.val], 0, 0, [0])

File ~/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py:4859, in OmeroGatewaySafeCallWrapper.__call__(self, *args, **kwargs)
   4857 except Exception as e:
   4858     self.debug(e.__class__.__name__, args, kwargs)
-> 4859     return self.handle_exception(e, *args, **kwargs)

File ~/OMERO.venv/lib/python3.10/site-packages/omero/gateway/__init__.py:4856, in OmeroGatewaySafeCallWrapper.__call__(self, *args, **kwargs)
   4854 def __call__(self, *args, **kwargs):
   4855     try:
-> 4856         return self.f(*args, **kwargs)
   4857     except Exception as e:
   4858         self.debug(e.__class__.__name__, args, kwargs)

File ~/OMERO.venv/lib/python3.10/site-packages/omero_api_IRoi_ice.py:826, in IRoiPrx.getShapeStatsRestricted(self, shapeIdList, zForUnattached, tForUnattached, channels, _ctx)
    825 def getShapeStatsRestricted(self, shapeIdList, zForUnattached, tForUnattached, channels, _ctx=None):
--> 826     return _M_omero.api.IRoi._op_getShapeStatsRestricted.invoke(self, ((shapeIdList, zForUnattached, tForUnattached, channels), _ctx))

InternalException: exception ::omero::InternalException
{
    serverStackTrace = ome.conditions.InternalException:  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:709)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:416)
    at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:125)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.tools.hibernate.ProxyCleanupFilter$Interceptor.invoke(ProxyCleanupFilter.java:249)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at ome.services.util.ServiceHandler.invoke(ServiceHandler.java:121)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy81.doWork(Unknown Source)
    at ome.services.util.Executor$Impl.execute(Executor.java:447)
    at ome.services.util.Executor$Impl.execute(Executor.java:392)
    at ome.services.throttling.Adapter.run(Adapter.java:50)
    at ome.services.throttling.InThreadThrottlingStrategy.runnableCall(InThreadThrottlingStrategy.java:89)
    at ome.services.blitz.impl.AbstractAmdServant.runnableCall(AbstractAmdServant.java:154)
    at ome.services.blitz.impl.RoiI.getShapeStatsRestricted_async(RoiI.java:252)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at omero.cmd.CallContext.invoke(CallContext.java:85)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy111.getShapeStatsRestricted_async(Unknown Source)
    at omero.api._IRoiTie.getShapeStatsRestricted_async(_IRoiTie.java:148)
    at omero.api._IRoiDisp.___getShapeStatsRestricted(_IRoiDisp.java:436)
    at omero.api._IRoiDisp.__dispatch(_IRoiDisp.java:657)
    at IceInternal.Incoming.invoke(Incoming.java:221)
    at Ice.ConnectionI.invokeAll(ConnectionI.java:2536)
    at Ice.ConnectionI.dispatch(ConnectionI.java:1145)
    at Ice.ConnectionI.message(ConnectionI.java:1056)
    at IceInternal.ThreadPool.run(ThreadPool.java:395)
    at IceInternal.ThreadPool.access$300(ThreadPool.java:12)
    at IceInternal.ThreadPool$EventHandlerThread.run(ThreadPool.java:832)
    at java.base/java.lang.Thread.run(Thread.java:829)

    serverExceptionClass = ome.conditions.InternalException
    message =  Wrapped Exception: (org.springframework.orm.hibernate3.HibernateSystemException):
failed to lazily initialize a collection, no session or session was closed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
}
"""

/cc @joshmoore @knabar @kkoz

imagesc-bot commented 1 year ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/batch-roi-export-py-omero-script/84527/5

joshmoore commented 1 year ago

As something of a first stab in the dark, it might be possible to include a join to the annotations of the shape in ome.services.roi.GeomTool:

https://github.com/ome/omero-blitz/blob/c500cdf0389b2fd9ef1e5e912279698819682f0e/src/main/java/ome/services/roi/GeomTool.java#L374-L380

though that could potentially add more overhead than you are interested in. At the other end of the spectrum would be to update this method to not work with objects and instead use the raw row information, but that's not going to be particularly fun.

knabar commented 1 year ago

Fetching annotation links and link children was one of the things we tried, but it did not resolve the issue. Not sure if more properties of the child (annotation) have to be fetched.

We did track down the line where the exception occurs: https://github.com/ome/omero-blitz/blob/c500cdf0389b2fd9ef1e5e912279698819682f0e/src/main/java/ome/services/roi/GeomTool.java#L439

Trying to unload the annotation links of the shape before that call also did not prevent the exception.

joshmoore commented 1 year ago

...I'm being told even more desperate measures were tried to no avail:

List results =
           session.createQuery(
               "select distinct s from Shape s " +
               "left join fetch s.transform t left join fetch s.roi r " +
               "left join fetch s.details details " +
               "left join details.externalInfo " +
               "left outer join fetch s.annotationLinks s_links " +
               "left outer join fetch s_link.child as ann " +
               "left outer join fetch ann.annotationLinks as al " +
               "left outer join fetch al.child " +
               "join fetch r.image i join fetch i.pixels p " +
               "where s.id in (:ids)").
           setParameterList("ids", shapeIds).list();

Ah, and thanks, @knabar. Let me see if that digs up any memories.

joshmoore commented 1 year ago

https://github.com/ome/omero-blitz/blob/c500cdf0389b2fd9ef1e5e912279698819682f0e/src/main/java/ome/services/roi/GeomTool.java#L581-L593

Usually IceMapping takes place outside of a transaction since you are in the process of preparing the graph for serialization. This Filter is going to walk through the entire graph when it really shouldn't. If I understand correctly, you tried unloading links here, in the ShapeMapper. But since you are in a transaction, that's a no-no. Would it be possible to just just ignore any of the fieldId's that aren't needed (most notably, annotations!)?

knabar commented 1 year ago

Annotations could absolutely be ignored here, but none of us knew how to go about that