Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Optimize imports before sort" is broken #7

Open
microdog opened this issue May 21, 2021 · 2 comments
Open

"Optimize imports before sort" is broken #7

microdog opened this issue May 21, 2021 · 2 comments

Comments

@microdog
Copy link

IDE error occurs when perform "Run isort" with "Optimize imports before sort" enabled.

PyCharm 2021.1.1 (Professional Edition)
Build #PY-211.7142.13, built on April 21, 2021
Runtime version: 11.0.9.1+11-b1145.63 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Non-Bundled Plugins: ..., com.github.urm8.isortconnect (0.0.12), ...
Unhandled exception in [CoroutineId(6172), "coroutine#6172":StandaloneCoroutine{Cancelling}@76f659e8, Dispatchers.IO]

com.intellij.util.IncorrectOperationException: Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor
	at com.intellij.pom.core.impl.PomModelImpl.startTransaction(PomModelImpl.java:270)
	at com.intellij.pom.core.impl.PomModelImpl.lambda$runTransaction$2(PomModelImpl.java:96)
	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.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:218)
	at com.intellij.pom.core.impl.PomModelImpl.runTransaction(PomModelImpl.java:93)
	at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:142)
	at com.intellij.psi.impl.source.tree.CompositeElement.removeChildrenInner(CompositeElement.java:833)
	at com.intellij.psi.impl.source.tree.CompositeElement.removeRange(CompositeElement.java:611)
	at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.removeChildren(CodeEditUtil.java:132)
	at com.intellij.psi.impl.source.PsiFileImpl.deleteChildRange(PsiFileImpl.java:844)
	at com.intellij.extapi.psi.ASTDelegatePsiElement.deleteElementFromParent(ASTDelegatePsiElement.java:342)
	at com.intellij.extapi.psi.ASTDelegatePsiElement.delete(ASTDelegatePsiElement.java:327)
	at com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesVisitor.optimizeImports(PyUnresolvedReferencesVisitor.java:570)
	at com.jetbrains.python.codeInsight.imports.PyImportOptimizer.lambda$processFile$0(PyImportOptimizer.java:79)
	at com.github.urm8.isortconnect.service.SorterService$optimizeImports$1.run(SorterService.kt:126)
	at com.intellij.openapi.application.WriteAction.lambda$runAndWait$2(WriteAction.java:134)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteActionWithClass(ApplicationImpl.java:947)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:973)
	at com.intellij.openapi.application.WriteAction.compute(WriteAction.java:115)
	at com.intellij.openapi.application.WriteAction.lambda$computeAndWait$3(WriteAction.java:164)
	at com.intellij.openapi.application.WriteThread.lambda$submit$0(WriteThread.java:27)
	at com.intellij.openapi.application.WriteThread.lambda$submit$1(WriteThread.java:44)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:218)
	at com.intellij.openapi.application.TransactionGuardImpl.access$200(TransactionGuardImpl.java:21)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:200)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:781)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLaterOnWriteThread$10(ApplicationImpl.java:770)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:133)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:46)
	at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:189)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:969)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:839)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:449)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:808)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:781)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:496)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
	Suppressed: java.lang.RuntimeException
		at com.intellij.openapi.application.WriteAction.computeAndWait(WriteAction.java:173)
		at com.intellij.openapi.application.WriteAction.runAndWait(WriteAction.java:133)
		at com.github.urm8.isortconnect.service.SorterService.optimizeImports(SorterService.kt:124)
		at com.github.urm8.isortconnect.service.SorterService.access$optimizeImports(SorterService.kt:32)
		at com.github.urm8.isortconnect.service.SorterService$sortImports$1.invokeSuspend(SorterService.kt:74)
		at com.github.urm8.isortconnect.service.SorterService$sortImports$1.invoke(SorterService.kt)
		at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$4.invokeSuspend(IntrinsicsJvm.kt:205)
		at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
		at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
		at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
		at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
		at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
		at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
@urm8
Copy link
Owner

urm8 commented May 22, 2021

wow, thats weird, will try to resolve asap :(
for some reason, only reproducable in stable build, wrapped the code that invokes optimizes imports in try/catch for now, will investigate it later

@microdog
Copy link
Author

microdog commented Jun 5, 2021

TL;DR
This issue can be solved by mounting project files into containers if you are deploying isortd using docker.

This issue occurs when I run isortd in docker, and the isortd reports isort.exceptions.FileSkipSetting errors.
If isortd is running directly in the host shell, everything works fine.

I find that the FileSkipSetting error is caused by the removal of disregard_skip flag,
and the error disappears after I add the disregard_skip flag back, but the sorting result is not correct.

Then I realize that the entire project tree might be needed to be accessible by isortd. After mounting my entire home into the container, the IsortConnect is working and the result is correct.

Maybe the README of isortd should be updated to document this issue. 😄

@github-staff github-staff deleted a comment from jigar-jstechno Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants