Import utils relative-first to avoid cross-extension shadowing - #2
Open
marc-lehner wants to merge 1 commit into
Open
marc-lehner wants to merge 1 commit into
marc-lehner wants to merge 1 commit into
Conversation
KNIME puts the module directory of every registered Python port-object converter on the sys.path of every Python gateway, not just the one belonging to the contributing extension. Another extension (PM4KNIME) contributes a top-level `utils` namespace package, so the bare `import utils` here bound the wrong module and `utils.category` raised AttributeError, breaking extension loading in any KNIME installation that has both extensions. Trying the relative import first binds this extension's own utils. The absolute import stays as the fallback for the test suite, which imports these modules without a package context. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
These nodes fail to load in a KNIME installation that also has the PM4KNIME extension:
KNIME adds the module directory of every registered Python port-object converter (and every
PythonValueFactorymodule's parent directory) to thesys.pathof every Python gateway — not just the one belonging to the contributing extension. PM4KNIME contributes a directory containing a top-levelutils/with no__init__.py, i.e. a namespace package namedutils.Three modules here do:
Normally the absolute
import utilsfails and the relative fallback runs. With such an extension installed the absolute import succeeds and binds the other extension's namespace package, which has no attributes at all — soutils.categoryraisesAttributeError, and the fallback never fires because it only catchesImportError.Any extension shipping a generically named top-level module can trigger this; PM4KNIME is just the one that surfaced it.
Fix
Swap the order: try the relative import first, keep the absolute one as the fallback for the test suite, which imports these modules without a package context. Three files — the ones activated in
src/__init__.py.Verification
utilsnamespace package onsys.path): old order →AttributeError: module 'utils' has no attribute 'category'; new order → binds the extension's ownutils.import standardizer_parentwithsrconsys.pathbindssrc/utils.py, withutils.categorypresent.pytest srcfails identically before and after this change — collection errors from a pre-existingModuleNotFoundError: No module named 'SA_Score'(RDKit Contrib not on the path in that environment). Not touched here.Notes
The other
utilsimporters in this repo (from new_rdkit_nodes import utilsinmolecule_grid_image.py,standardizer_normalize.py,visualize_*.py,rgroup_highlight.py) reference a package name that no longer exists, but all of those modules are commented out insrc/__init__.py, so they are dormant and left alone here.🤖 Generated with Claude Code