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

SparkleUpdateInfoProvider crashes with "AttributeError: 'str' object has no attribute 'decode'" #920

Open
workflowsguy opened this issue Dec 14, 2023 · 9 comments

Comments

@workflowsguy
Copy link

Describe the problem
When running the recipe com.github.autopkg.hjuutilainen-recipes/CodeRunner/CodeRunner2.munki.recipe, SparkleUpdateInfoProvider crashes autopkg.

AutoPkg output

SparkleUpdateInfoProvider
{'Input': {'appcast_url': 'https://coderunnerapp.com/appcast.xml',
           'pkginfo_keys_to_copy_from_sparkle_feed': ['description']}}
SparkleUpdateInfoProvider: Curl command: ['/opt/local/bin/curl', '--compressed', '--location', 'https://coderunnerapp.com/appcast.xml']
SparkleUpdateInfoProvider: Items in feed: 22
SparkleUpdateInfoProvider: Items in default channel: 22
SparkleUpdateInfoProvider: Version retrieved from appcast: 67365
SparkleUpdateInfoProvider: User-facing version retrieved from appcast: 4.3
Traceback (most recent call last):
  File "/Library/AutoPkg/autopkglib/__init__.py", line 878, in process
    self.env = processor.process()
  File "/Library/AutoPkg/autopkglib/__init__.py", line 661, in process
    self.main()
  File "/Library/AutoPkg/autopkglib/SparkleUpdateInfoProvider.py", line 354, in main
    pkginfo = self.handle_pkginfo(latest)
  File "/Library/AutoPkg/autopkglib/SparkleUpdateInfoProvider.py", line 301, in handle_pkginfo
    pkginfo["description"] = description.decode("UTF-8")
AttributeError: 'str' object has no attribute 'decode'
  File "/Library/AutoPkg/autopkglib/__init__.py", line 878, in process
    self.env = processor.process()
'str' object has no attribute 'decode'
Failed.

Expected behavior
Recipe should download the new app release successfully. In case of an error in the XML file, autopkg should exit gracefully, pointing out the issue that it encounterd.

Version (please complete the following information):

  • OS version: 10.13.6
  • AutoPkg Version: 3.0RC2
@homebysix
Copy link
Member

I'm not able to reproduce this on macOS 14.2 with 3.0RC2:

SparkleUpdateInfoProvider
{'Input': {'appcast_url': 'https://coderunnerapp.com/appcast.xml'}}
SparkleUpdateInfoProvider: Items in feed: 22
SparkleUpdateInfoProvider: Items in default channel: 22
SparkleUpdateInfoProvider: Version retrieved from appcast: 67365
SparkleUpdateInfoProvider: User-facing version retrieved from appcast: 4.3
SparkleUpdateInfoProvider: Found URL https://coderunnerapp.com/download/update/CodeRunner-4.3.zip

@workflowsguy What version of the included Python do you have?

% /usr/local/autopkg/python --version
Python 3.10.4

@workflowsguy
Copy link
Author

workflowsguy commented Dec 18, 2023

I have tested this on two different Macs, with maOS 10.13.6 and 13.6.3. Both have AutoPkg 3.0RC2, and both give

❯ /usr/local/autopkg/python --version
Python 3.10.4

On both machines execution of the recipe fails.

I deduct from this SO answer that the 'decode' part of the statement

pkginfo["description"] = description.decode("UTF-8")

is not necessary because the string is already UTF8-encoded.
But then I wonder why it does not fail when you tried it.

@nmcspadden
Copy link
Contributor

nmcspadden commented Dec 18, 2023 via email

@workflowsguy
Copy link
Author

So my tests show this:

SparkleUpdateInfoProvider.py on line 301 has the statement

                pkginfo["description"] = description.decode("UTF-8")

description is of type str. Since Python 3, the str class no longer has a decode method, the string data is already utf-8-encoded. So the .decode("UTF-8") part of the line will cause an error. Maybe this line was overlooked in a code update?

Thus, when the line is changed to

                pkginfo["description"] = description

the recipe executes correctly.

As to why the recipe fails on our machines but not on yours, this might be caused by the fact that I am actually running an override of the original recipe. It seems that a change I have made in the override triggers this issue.

Can you please verify this?

@workflowsguy
Copy link
Author

So my tests show this:

SparkleUpdateInfoProvider.py on line 301 has the statement

                pkginfo["description"] = description.decode("UTF-8")

description is of type str. Since Python 3, the str class no longer has a decode method, the string data is already utf-8-encoded. So the .decode("UTF-8") part of the line will cause an error. Maybe this line was overlooked in a code update?

Thus, when the line is changed to

                pkginfo["description"] = description

the recipe executes correctly.

As to why the recipe fails on our machines but not on yours, this was caused by the fact that I am actually running an override of the original recipe.
It contained an unnecessary

		</dict>
		<key>pkginfo_keys_to_copy_from_sparkle_feed</key>
		<array>
			<string>description</string>
		</array>

entry that triggered this issue.

Can you please verify the decode problem?

@nmcspadden
Copy link
Contributor

nmcspadden commented Dec 19, 2023 via email

@workflowsguy
Copy link
Author

Here is an override to the original recipe that only adds the key that crashes SparkleUpdateInfoProvider.
(Had to add a txtextension, otherwise GitHub refuses to upload)

CodeRunner2-Override.munki.recipe.txt

@macmule
Copy link
Member

macmule commented Dec 21, 2023

I can confirm that dropping the .decode(utf-8) resolves the errors... BUT the resulting PkgInfo isn't using the description from the sparkle feed anyways.. is that intentional @workflowsguy?

@workflowsguy
Copy link
Author

workflowsguy commented Dec 27, 2023

@macmule

BUT the resulting PkgInfo isn't using the description from the sparkle feed anyways.. is that intentional @workflowsguy?

I don't know how and why this part got into the actual override in the first place. I only discovered that it was there while investigating the exception it triggered. As you correctly observed, it does not have any purpose in the override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants