pydantic-pycharm-plugin
pydantic-pycharm-plugin copied to clipboard
Non-idempotent computation
Describe the bug I receive very often a fatal IDE error.
java.lang.Throwable: Non-idempotent computation: it returns different results when invoked multiple times or on different threads:
MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@61e7c7bc}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest} != MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@679cd73b}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}
which is element of MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@61e7c7bc}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0 and MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@679cd73b}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0
which is 0th element of [MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@61e7c7bc}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0, MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@1e8842d7}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0] and [MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@679cd73b}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0, MyInstanceElement{myClass=PyClass: QueryDictmember={resolve=PsiParameterizedCachedValue{com.jetbrains.python.codeInsight.PyCustomMember$$Lambda$5486/0x0000000802d66c40@39803054}}node=Element(Py:TARGET_EXPRESSION), myContext=PyClass: HttpRequest}@0]
Recomputation gives [Lcom.intellij.psi.ResolveResult;@27604f35 (class [Lcom.intellij.psi.ResolveResult;) which is different from both values
Recomputation log:
Resolving PyQualifiedReference(PyReferenceExpression: GET,com.jetbrains.python.psi.resolve.PyResolveContext@147df0e1) of class com.jetbrains.python.psi.impl.references.PyQualifiedReference
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:161)
at com.intellij.util.IdempotenceChecker.reportFailure(IdempotenceChecker.java:90)
at com.intellij.util.IdempotenceChecker.checkEquivalence(IdempotenceChecker.java:77)
at com.intellij.psi.impl.source.resolve.ResolveCache.cache(ResolveCache.java:322)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolve(ResolveCache.java:249)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolve(ResolveCache.java:154)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:169)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:162)
at com.jetbrains.python.psi.impl.references.PyReferenceImpl.multiResolve(PyReferenceImpl.java:95)
at com.koxudaxi.pydantic.PydanticKt.getResolveElements(Pydantic.kt:239)
at com.koxudaxi.pydantic.PydanticKt.getResolvedPsiElements(Pydantic.kt:246)
at com.koxudaxi.pydantic.PydanticDataclassTypeProvider.getPydanticDataclass(PydanticDataclassTypeProvider.kt:62)
at com.koxudaxi.pydantic.PydanticDataclassTypeProvider.getReferenceExpressionType(PydanticDataclassTypeProvider.kt:26)
at com.jetbrains.python.psi.impl.PyReferenceExpressionImpl.getTypeFromProviders(PyReferenceExpressionImpl.java:385)
at com.jetbrains.python.psi.impl.PyReferenceExpressionImpl.getType(PyReferenceExpressionImpl.java:219)
at com.jetbrains.python.psi.types.TypeEvalContext.lambda$getType$0(TypeEvalContext.java:180)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:43)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
at com.jetbrains.python.psi.types.TypeEvalContext.getType(TypeEvalContext.java:169)
at com.jetbrains.python.psi.impl.references.PyQualifiedReference.resolveInner(PyQualifiedReference.java:81)
at com.jetbrains.python.psi.impl.references.PyReferenceImpl.multiResolveInner(PyReferenceImpl.java:108)
at com.jetbrains.python.psi.impl.references.PyReferenceImpl$CachingResolver.resolve(PyReferenceImpl.java:777)
at com.jetbrains.python.psi.impl.references.PyReferenceImpl$CachingResolver.resolve(PyReferenceImpl.java:772)
at com.intellij.psi.impl.source.resolve.ResolveCache.lambda$resolve$1(ResolveCache.java:154)
at com.intellij.openapi.util.Computable.get(Computable.java:17)
at com.intellij.psi.impl.source.resolve.ResolveCache.lambda$loggingResolver$4(ResolveCache.java:260)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:43)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolve(ResolveCache.java:237)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolve(ResolveCache.java:154)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:169)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:162)
at com.jetbrains.python.psi.impl.references.PyReferenceImpl.multiResolve(PyReferenceImpl.java:95)
at com.jetbrains.python.psi.PyUtil.multiResolveTopPriority(PyUtil.java:514)
at com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider.tryResolvingWithAliases(PyTypingTypeProvider.java:1383)
at com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider.tryResolving(PyTypingTypeProvider.java:1372)
at com.jetbrains.python.codeInsight.typing.PyTypingTypeProvider.resolveToQualifiedNames(PyTypingTypeProvider.java:1438)
at com.jetbrains.python.codeInsight.typing.PyTypedDictTypeProvider$Companion.isTypedDict(PyTypedDictTypeProvider.kt:42)
at com.jetbrains.python.codeInsight.typing.PyTypedDictTypeProvider$Companion.getTypedDictTypeForCallee(PyTypedDictTypeProvider.kt:111)
at com.jetbrains.python.codeInsight.typing.PyTypedDictTypeProvider$Companion.access$getTypedDictTypeForCallee(PyTypedDictTypeProvider.kt:38)
at com.jetbrains.python.codeInsight.typing.PyTypedDictTypeProvider.getReferenceExpressionType(PyTypedDictTypeProvider.kt:27)
at com.jetbrains.python.psi.impl.PyReferenceExpressionImpl.getTypeFromProviders(PyReferenceExpressionImpl.java:385)
at com.jetbrains.python.psi.impl.PyReferenceExpressionImpl.getType(PyReferenceExpressionImpl.java:219)
at com.jetbrains.python.psi.types.TypeEvalContext.lambda$getType$0(TypeEvalContext.java:180)
at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:43)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:68)
at com.jetbrains.python.psi.types.TypeEvalContext.getType(TypeEvalContext.java:169)
at com.jetbrains.python.inspections.PyCallingNonCallableInspection.isCallable(PyCallingNonCallableInspection.java:92)
at com.jetbrains.python.inspections.PyCallingNonCallableInspection$Visitor.checkCallable(PyCallingNonCallableInspection.java:70)
at com.jetbrains.python.inspections.PyCallingNonCallableInspection$Visitor.visitPyCallExpression(PyCallingNonCallableInspection.java:54)
at com.jetbrains.python.psi.impl.PyCallExpressionImpl.acceptPyVisitor(PyCallExpressionImpl.java:29)
at com.jetbrains.python.psi.impl.PyBaseElementImpl.accept(PyBaseElementImpl.java:69)
at com.intellij.codeInspection.InspectionEngine.acceptElements(InspectionEngine.java:65)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitRestElementsAndCleanup$7(LocalInspectionsPass.java:346)
at com.intellij.util.AstLoadingFilter.lambda$toComputable$2(AstLoadingFilter.java:174)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:132)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:121)
at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:111)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.lambda$visitRestElementsAndCleanup$10(LocalInspectionsPass.java:346)
at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:136)
at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:149)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1091)
at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:92)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:688)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:634)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:64)
at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:104)
at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:83)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:167)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:178)
at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:83)
at com.intellij.concurrency.JobLauncherImpl.invokeConcurrentlyUnderProgress(JobLauncherImpl.java:61)
at com.intellij.concurrency.JobLauncher.invokeConcurrentlyUnderProgress(JobLauncher.java:49)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.visitRestElementsAndCleanup(LocalInspectionsPass.java:366)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:208)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:119)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:56)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:400)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1096)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:393)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:688)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:634)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:64)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:392)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:368)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:167)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:178)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:366)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:188)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Environments (please complete the following information):
- PyCharm Professional 2021.1
- Ubuntu 20.04.2
- pydantic==1.7.3
- Plugin version 0.3.0
@pokidovea Thank you for creating this issue. Can you show me your python code?
I have a lot of code and it belongs to my company. What kind of issue do you want to see? May be it will reduce the search
I guess pydantic dataclass has related the error. :thinking:
at com.koxudaxi.pydantic.PydanticKt.getResolveElements(Pydantic.kt:239)
at com.koxudaxi.pydantic.PydanticKt.getResolvedPsiElements(Pydantic.kt:246)
at com.koxudaxi.pydantic.PydanticDataclassTypeProvider.getPydanticDataclass(PydanticDataclassTypeProvider.kt:62)
at com.koxudaxi.pydantic.PydanticDataclassTypeProvider.getReferenceExpressionType(PydanticDataclassTypeProvider.kt:26)
There is no place in project, where we could use pydantic dataclasses. Only pydantic models and standard python dataclasses. I can show you a part of our code, but there are a lot of pydantic models and I don't know which causes the exception.
I checked your error and the code of the plugin again.
The error happened before detecting the pydantic model and dataclass
PyCharm failed to resolve HttpRequest
class.
Did you know about the class?
And I will investigate the error. Thank you.
Yes, this class is from Django package (web framework). It's a regular python class, even not a dataclass. Strange. How your plugin connected to it?
This plugin searches pydantic dataclass from all python objects. Libraries often use pydantic models. So checking all objects in the library.
I don't see an error. But, Django is a huge framework. The searching way might not correct.
I will check a better way.
@pokidovea
I'm sorry for my too-late fix.
I have released a new version v0.4.0 in the market
The version dropped unnecessary resolving for an object reference.
It means the update reduces CPU load and fixes unexpected errors.
I closed the PR because the root cause method was removed from the plugin's source code. Thank you.