OHDSI / WebAPI

OHDSI WebAPI contains all OHDSI services that can be called from OHDSI applications
Apache License 2.0
126 stars 156 forks source link

Error fetching generations for CohortPathways #2360

Closed chrisknoll closed 2 months ago

chrisknoll commented 2 months ago

Expected behavior

Opening a cohort pathway and navigating to executions should show a list of data sources.

Actual behavior

Empty table is returned, with no sources. Exception in Logs:

2024-04-11 13:31:58.200 ERROR https-jsse-nio-8443-exec-10 org.ohdsi.webapi.util.GenericExceptionMapper - [] - org.springframework.core.convert.ConversionFailedException: Failed to convert from type [org.ohdsi.webapi.pathway.domain.PathwayAnalysisGenerationEntity] to type [org.ohdsi.webapi.common.generation.CommonGenerationDTO] for value 'org.ohdsi.webapi.pathway.domain.PathwayAnalysisGenerationEntity@2cf1b6cb'; nested exception is org.hibernate.LazyInitializationException: could not initialize proxy [org.ohdsi.webapi.source.Source#139] - no Session
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:44)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187)
    at com.odysseusinc.arachne.commons.utils.ConverterUtils.lambda$convertCollection$0(ConverterUtils.java:65)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
    at com.odysseusinc.arachne.commons.utils.ConverterUtils.convertCollection(ConverterUtils.java:69)
    at com.odysseusinc.arachne.commons.utils.ConverterUtils.convertList(ConverterUtils.java:59)
    at com.odysseusinc.arachne.commons.utils.ConverterUtils.convertList(ConverterUtils.java:49)
    at org.ohdsi.webapi.pathway.PathwayController.getPathwayGenerations(PathwayController.java:372)
    at org.ohdsi.webapi.pathway.PathwayController$$FastClassBySpringCGLIB$$ce5eef31.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:84)
    at org.ohdsi.webapi.audittrail.AuditTrailAspect.auditLog(AuditTrailAspect.java:92)
    at sun.reflect.GeneratedMethodAccessor265.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Steps to reproduce behavior

Open existing cohort pathway, navigate to executions. It is not clear if there were prior executions or of data sources have changed since this error was discovered, and it could be Tomcat 9, but will attempt to trace through code to investigate the 'closed session' error.

chrisknoll commented 2 months ago

The no session seems to relate to fetching extra attributes from an Entity Bean after the session is closed. To keep a session open, you have to have an active trasactions...so the theory is that the transaction was being closed early.

At first I thought this was related to how transactions were being managed: CohortDefinitionService wraps the fetch function in Transactional, the CohortCharacterization uses an entity graph to fetch all associated elements in one go, and Pathways wasn't doing either so I thought that was it. HOWEVER, in my test enviornment, I have 2 different instances (let's call them 66 and 59) where the 66 one would load correctly, and 59 would lead to no-session. This is very odd because it should always get no-session or not. I need to investigate further.

To make matters worse, after returning to this, neither request leads to a no-sesson error now! But will keep investigating to understand why it happened in the first place.

Edit: after closing and opening the pathway design from atlas UI it caused the no-sesson again....but changing the URL from one to another didn't seem to lead to the error...again, it's a mystery, trying to investigate.

Edit 2: Ok, i understand now: changing the URL (to quickly go from one to another) was failing, but the results showin in the list were from the prior cohort definition. this is bad because switching to another pathway should 'clear' the generations but it left it behidn (probably because of the error fetchign results).