feat: Fix import error (issue #6924) - #6926
Merged
Merged
Conversation
`importer.py` calls `importlib.util.find_spec()` but the file only actually imports `importlib` by itself. Up until now we've gotten away with it as something else has always imported `importlib.util` for us "by accident", but if an end consumer imports `cloud-init` as a library (i.e. `ubuntu-pro-client`) there's no guarantee that will happen. It happened in canonical#6924 so let's fix it now.
kajiya3141
marked this pull request as ready for review
July 8, 2026 22:11
blackboxsw
approved these changes
Jul 10, 2026
blackboxsw
left a comment
Collaborator
There was a problem hiding this comment.
Thank you @kajiya314~1 This is the correct and least impact fix to make.
I verified failure path using the following procedure
lxc launch ubuntu-minimal:bionic b-min
lxc exec b-min -- apt install ubuntu-pro-client
lxc exec b-min -- python3 /usr/lib/ubuntu-advantage/auto_attach.py
...
File "/usr/lib/python3/dist-packages/cloudinit/importer.py", line 52, in find_module
if not importlib.util.find_spec(full_path):
AttributeError: module 'importlib' has no attribute 'ut=il'
With your patch applied no traceback:
$ python3 /usr/lib/ubuntu-advantage/auto_attach.py
["2026-07-10T16:47:33.571", "ERROR", "ubuntupro.lib.auto_attach", "main", 102, "The LXD host does not allow guest auto attach", {}]
["2026-07-10T16:47:33.572", "INFO", "ubuntupro.lib.auto_attach", "main", 104, "creating flag file to trigger retries", {}]
Given that cherry picking this will target bionic images I think keeping this as simple as possible will make that backport easier as well.
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.
Proposed Commit Message
feat: Fix import error (issue #6924)
importer.pycallsimportlib.util.find_spec()but the file only actually importsimportlibby itself.
Up until now we've gotten away with it as something else has always imported
importlib.utilfor us "by accident", but if an end consumer importscloud-initas a library (i.e.ubuntu-pro-client) there's no guarantee that will happen. It happened in #6924 so let's fix it now.Test Steps
Tested in a LP build with the same functional change in our bootstraps:
it builds fine and
auto-attachis now fixed 🥳