Bug#1090351: /usr/lib/python3/dist-packages/aptsources/distro.py: Calling .lower() method on a 'None' type variable (file: aptsources/distro.py, line 544, function: get_distro)
Package: python3-apt
Version: 2.9.2
Severity: important
File: /usr/lib/python3/dist-packages/aptsources/distro.py
Dear Maintainer,
* What led up to the situation?: Setup a node with ansible.
* What exactly did you do (or not do) that was effective (or
ineffective)? Run ansible as usual in order to setup a source file
for apt.
* What was the outcome of this action? Anisble run fails with
```
Traceback (most recent call last):
File "/home/glennie/.ansible/tmp/ansible-tmp-1734426175.6180859-3979780-111839269724897/AnsiballZ_apt_repository.py", line 259, in <module>
_ansiballz_main()
File "/home/glennie/.ansible/tmp/ansible-tmp-1734426175.6180859-3979780-111839269724897/AnsiballZ_apt_repository.py", line 249, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/glennie/.ansible/tmp/ansible-tmp-1734426175.6180859-3979780-111839269724897/AnsiballZ_apt_repository.py", line 122, in invoke_module
runpy.run_module(mod_name='ansible.modules.apt_repository', init_globals=dict(_module_fqn='ansible.modules.apt_repository', _modlib_path=modlib_path),
File "<frozen runpy>", line 226, in run_module
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/tmp/ansible_ansible.builtin.apt_repository_payload_l931syp9/ansible_ansible.builtin.apt_repository_payload.zip/ansible/modules/apt_repository.py", line 195, in <module>
File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 544, in get_distro
id = id.lower()
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'
msg: |-
MODULE FAILURE: No start of json char found
See stdout/stderr for the exact error
```
A simple way to reproduce this is bug is to start a python REPL, then
type:
```
import aptsources.distro as aptsources_distro
distro = aptsources_distro.get_distro()
```
>From what I see, the bug lies at line 544, in `aptsources/distro.py`.
`id` is initalized to `None` in the function signature(line: 529). Then on
line 544, I see `id = id.lower()`. If `id` is not set by the caller, it
fails (as ansible seems do).
May be, the line 544 should be be rewritten to:
```
if id is not None:
id = id.lower()
```
* What outcome did you expect instead? Ansible should not fail here
-- System Information:
Debian Release: trixie/sid
APT prefers unstable
APT policy: (990, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 6.11.9-amd64 (SMP w/8 CPU threads; PREEMPT)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to en_US.UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages python3-apt depends on:
ii distro-info-data 0.63
ii libapt-pkg6.0t64 2.9.17
ii libc6 2.40-4
ii libgcc-s1 14.2.0-8
ii libstdc++6 14.2.0-8
ii python-apt-common 2.9.2
ii python3 3.12.7-1
Versions of packages python3-apt recommends:
ii iso-codes 4.17.0-1
ii lsb-release 12.1-1
Versions of packages python3-apt suggests:
ii apt 2.9.17
pn python-apt-doc <none>
-- no debconf information
Reply to: