Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (). If you're a Red Hat customer, please continue to file support cases via the . If you're not, please head to the "" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult . That failing, please send an e-mail to the RH Jira admins at to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2091636

Summary: python3-dnf wrong indentation level in substitutions.py:64
Product: Red Hat Enterprise Linux 9 Reporter: space88man <shihping.chan>
Component: dnfAssignee: Jaroslav Mracek <jmracek>
Status: CLOSED ERRATA QA Contact: Tomáš Bajer <tbajer>
Severity: unspecified Docs Contact:
Priority: medium
Version: 9.0CC: james.antill, mbanas, mblaha, tbajer
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified
OS: Unspecified
Whiteboard:
dnf-4.14.0-1.el9 No Doc Update
---
: 2110912 (view as bug list)
2023-05-09 08:18:18 UTC Bug
--- ---
---
---
--- RHEL 7.3 requirements from Atomic Host:
---
Bug Depends On:
Bug Blocks: 2110912

Description space88man 2022-05-30 14:34:45 UTC
Description of problem:

python3-dnf:
If the vars directory happens to have a non-file, the var val is not set
and an uncaught Exception is triggered


Version-Release number of selected component (if applicable):
4.10.0-5.el9_0

How reproducible:
Depends on how python parses the varsdir

Steps to Reproduce:
1. In the dnf varsdir add random non-files (like links)
2.
3.

Actual results:
Traceback (most recent call last):
 File "/bin/reposync", line 101, in <module>
 main.user_main(MAPPING[command] + args, exit_code=True)
 File "/usr/lib/python3.9/site-packages/dnf/cli/main.py", line 201, in user_main
 errcode = main(args)
 File "/usr/lib/python3.9/site-packages/dnf/cli/main.py", line 67, in main
 return _main(base, args, cli_class, option_parser_class)
 File "/usr/lib/python3.9/site-packages/dnf/cli/main.py", line 102, in _main
 cli.configure(list(map(ucd, args)), option_parser())
 File "/usr/lib/python3.9/site-packages/dnf/cli/cli.py", line 799, in configure
 self._read_conf_file(opts.releasever)
 File "/usr/lib/python3.9/site-packages/dnf/cli/cli.py", line 933, in _read_conf_file
 subst.update_from_etc(from_root, varsdir=conf._get_value('varsdir'))
 File "/usr/lib/python3.9/site-packages/dnf/conf/substitutions.py", line 64, in update_from_etc
 self[fsvar] = val
UnboundLocalError: local variable 'val' referenced before assignment



Expected results:
Non-files are ignored

Additional info:

The indentation level at line 64 looks wrong perhaps?
 44 def update_from_etc(self, installroot, varsdir=("/etc/yum/vars/", "/etc/dnf/vars/")):
 45 # :api
 46 
 47 for vars_path in varsdir:
 48 fsvars = []
 49 try:
 50 dir_fsvars = os.path.join(installroot, vars_path.lstrip('/'))
 51 fsvars = os.listdir(dir_fsvars)
 52 except OSError:
 53 continue
 54 for fsvar in fsvars:
 55 filepath = os.path.join(dir_fsvars, fsvar)
 56 if os.path.isfile(filepath):
 57 try:
 58 with open(filepath) as fp:
 59 val = fp.readline()
 60 if val and val[-1] == '\n':
 61 val = val[:-1]
 62 except (OSError, IOError) as exc:
 63 continue
 64 self[fsvar] = val

Comment 1 space88man 2022-05-30 14:39:31 UTC
To trigger this error I added symbolic links to directories; the error depends on how python scans the directory.

1. If python encounters a non-file (e.g link to directory) the error will be triggered
2. if python encounters a file, the var val will be set from this file, so in future interations self[fsvar] = val will work as it will reuse the last successful value from readline()

Comment 3 Jaroslav Mracek 2022-07-11 10:41:25 UTC
I created a PR that resolves the issue - https://github.com/rpm-software-management/dnf/pull/1834. The bug still requires a test for our CI.

Comment 4 Jaroslav Mracek 2022-07-26 07:46:14 UTC
CI tests: https://github.com/rpm-software-management/ci-dnf-stack/pull/1136

Comment 14 errata-xmlrpc 2023-05-09 08:18:18 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (dnf bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2490