Can't upload theme from file

AI-generated summary

A user, pfaffman, encountered an issue with importing a theme from a file, where the “upload” button didn’t work after selecting the file. Pad_Pors reported a similar issue with themes containing attached files. However, jomaxro couldn’t reproduce the problem.

pfaffman provided an error log, which suggested an “Unknown type passed to set field” error. cpradio suspected the issue was related to an upload/asset in the theme file. Upon inspection, pfaffman found a section in the JSON file referencing an uploaded asset. cpradio suggested commenting out the filename, but this didn’t resolve the issue.

However, pfaffman eventually found that removing the upload section solved the problem. cpradio and pfaffman confirmed that the issue was related to the upload. sam explained that the problem is due to a change in how uploads are handled in theme exports, where they are now base64 encoded in the JSON payload.

I just tried to import a theme from a file. When I select “from my device” I get the selector and choose the file, but then the “upload” button doesn’t do anything. I tested on two instances Discourse 1.9.0.beta13 and Discourse 1.9.0.beta14.

Tested Chome and Firefox on Linux.

3 Likes

I had the same problem with themes which has some files attached (as uploads). simple css-html themes without any attachment were ok.

2 Likes

Hmm…I can’t reproduce this on a test hosted site. I exported and uploaded Theme Test and ran into no issues.

2 Likes

Well here’s an error log:

  Parameters: {"theme"=>#<ActionDispatch::Http::UploadedFile:0x00007fc32bc88958 @tempfile=#<Tempfile:/tmp/RackMultipart20171103-338-1gjeut6.json>, @original_filename="mrf-tweaks.dcstyle.json", @content_type="application/json", @headers="Content-Disposition: form-data; name=\"theme\"; filename=\"mrf-tweaks.dcstyle.json\"\r\nContent-Type: application/json\r\n">}
Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.5ms)
RuntimeError (Unknown type  passed to set field)
/var/www/discourse/app/models/theme.rb:253:in `set_field'

This is strange because I downloaded this file from this very same server before uploading a new import.

I’m assuming it has an upload/asset? I think that is the key to the error (if that is true for your case)

1 Like

Yes. I see it now. Like

      {
        "name": "logo-square",
        "target": "common",
        "value": "",
        "type_id": 2,
        "upload_id": 7612,
        "url": "/uploads/default/original/2X/e/eb4f8eaa4183d055ad75c5dfcf5010b67248862a.png",
        "filename": "site-Square.png"
      },

If you comment out the filename for now (and re-upload it after), does it work?

Hmm. I tried deleting the section I included above, and then tried deleting the “filename”: “fil.png” part (and preceding comma). But no joy.

You want me to PM you the file?

Sure, I can play around with it on my sandbox tonight (or should be able to)

1 Like

Removing the upload solved the problem. Definitely seems like a bug, though.

Thanks, @cpradio!

4 Likes

I can definitely recreate the issue when there is an asset/upload as part of the theme, once that is removed, the import works fine.

5 Likes

This is a rather hairy change, uploads are now base64 encoded in the json payload for theme export.

https://github.com/discourse/discourse/commit/47e4c9bb468fca10f4818df3bc44a67990eb75aa

8 Likes

This topic was automatically closed after 25 hours. New replies are no longer allowed.