utils.py attempts to access unknown locale.format attribute

Bug #2045507 reported by David Levine
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
HPLIP
New
Undecided
Unassigned

Bug Description

HP Linux Imaging and Printing System (ver. 3.23.8)
Scan Utility ver. 2.2
Fedora 39

This command, with an area br-x (third value) of 86 mm or less:
$ hp-scan --area=0,0,86,100 --file=test.pdf

Results in this traceback:
Closing device.
Traceback (most recent call last):
  File "/bin/hp-scan", line 1353, in <module>
    utils.format_bytes(bytes_read))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/hplip/base/utils.py", line 482, in format_bytes
    return ''.join([commafy(s), ' B'])
                    ^^^^^^^^^^
  File "/usr/share/hplip/base/utils.py", line 477, in commafy
    return locale.format("%s", val, grouping=True)
           ^^^^^^^^^^^^^
AttributeError: module 'locale' has no attribute 'format'. Did you mean: '_format'?

Oddly, increasing the third (br-x) value in the area to 87 or more resolves the issue.

Changing "locale.format" to "locale._format" here also resolves the issue, but I am not sure if it is correct:
/usr/share/hplip/base# diff utils.py{,.ORIGINAL}
477c477
< return locale._format("%s", val, grouping=True)
---
> return locale.format("%s", val, grouping=True)

Revision history for this message
David Levine (levinedl) wrote :
David Levine (levinedl)
description: updated
Revision history for this message
David Levine (levinedl) wrote :

HP Linux Imaging and Printing System (ver. 3.23.12)
Scan Utility ver. 2.2
Fedora 39

I get the same error when I specify --resolution.

Revision history for this message
Denis Shulyaka (shulyaka) wrote :

I believe the function should be updated to `format_string`. Neither `format` nor `_format` are documented.

Revision history for this message
zdohnal (zdohnal) wrote :

Hi,

I saw the issue as https://bugzilla.redhat.com/show_bug.cgi?id=2270031 - I've checked help page for locale and I agree with Denis - we should use the method 'format_string'.

I created the attached patch and now I'm building updates for Fedora 38+

Revision history for this message
David Levine (levinedl) wrote :

Verified that 'format_string' fixes the reported issue on Fedora 39.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.