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

AttributeError: 'NoneType' object has no attribute 'get' #1480

Closed
Alffernandez opened this issue Jun 16, 2023 · 0 comments · Fixed by #1479
Closed

AttributeError: 'NoneType' object has no attribute 'get' #1480

Alffernandez opened this issue Jun 16, 2023 · 0 comments · Fixed by #1479
Assignees

Comments

@Alffernandez
Copy link

Version
Server version: 4.6.4
Pulp Ansible Version: 0.15.0

Describe the bug
If there are collections published without meta/runtime.yml in the Automation Hub, the upgrade from Automation Hub 4.2 (AAP 1.2) to Automation Hub 4.6 (AAP 2.3) fails with the following error:

TASK [pulp.pulp_installer.pulp_database_config : Run database migrations] ******
fatal: [aap01dhub1new.launcher.int.abnamro.com]: FAILED! => {"changed": true, "cmd": ["/usr/bin/pulpcore-manager", "migrate", "--no-input"],
......
......
  File \"/usr/lib/python3.9/site-packages/pulp_ansible/app/migrations/0030_collectionversion_requires_ansible.py\", line 33, in set_requires_ansible_and_manifest_and_files_json", "    collection_version.requires_ansible = runtime_yaml.get(\"requires_ansible\")", "AttributeError: 'NoneType' object has no attribute 'get'"], 

To Reproduce

  1. Install Automation Hub 4.2 (Ansible Automation Platform 1.2.7 Setup Bundle)
  2. Publish a collection/s without meta/runtime.yml.
  3. Upgrade to Automation Hub 4.6 (Ansible Automation Platform 2.3 Setup Bundle)

Expected behavior
The installer should show a Warning and skip that task if there is a collection without runtime.yml

Additional context
After applying the patch provided by Matthias Dellweg, the upgrade finishes successfully.

           if runtime_metadata:
                try:
                    runtime_yaml = yaml.safe_load(runtime_metadata)
                except YAMLError:
                    log.warning(
                        "CollectionVersion: '{namespace}.{name}-{version}' - 'meta/runtime.yml' is invalid yaml.".format(
                            namespace=collection_version.namespace, name=collection_version.name, version=collection_version.version
                        )
                    )
                else:
                    try:
                        collection_version.requires_ansible = runtime_yaml.get("requires_ansible")
                    except AttributeError:
                        log.warning(
                            "CollectionVersion: '{namespace}.{name}-{version}' - 'meta/runtime.yml' is missing key 'requires_ansible'.".format(
                                namespace=collection_version.namespace, name=collection_version.name, version=collection_version.version
                            )
                        )

            manifest = get_file_obj_from_tarball(tar, "MANIFEST.json", artifact.file.name, raise_exc=False)
            if manifest:
                try:
                    collection_version.manifest = json.load(manifest)
                except JSONDecodeError:
                    log.warning(
                        "CollectionVersion: '{namespace}.{name}-{version}' - 'MANIFEST.json' is invalid json.".format(
                            namespace=collection_version.namespace, name=collection_version.name, version=collection_version.version
                        )
                    )

            files = get_file_obj_from_tarball(tar, "FILES.json", artifact.file.name, raise_exc=False)
            if files:
                try:
                    collection_version.files = json.load(files)
                except JSONDecodeError:
                    log.warning(
                        "CollectionVersion: '{namespace}.{name}-{version}' - 'FILES.json' is invalid json.".format(
                            namespace=collection_version.namespace, name=collection_version.name, version=collection_version.version
                        )
                    )
            collection_version.save()
@mdellweg mdellweg self-assigned this Jun 16, 2023
mdellweg added a commit to mdellweg/pulp_ansible that referenced this issue Jun 16, 2023
@mdellweg mdellweg linked a pull request Jun 16, 2023 that will close this issue
mdellweg added a commit to mdellweg/pulp_ansible that referenced this issue Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants