{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/65537168","id":65537168,"diff_hunk":"@@ -351,27 +367,30 @@ def generate_thumbnail(self, content, tempfile_path=None, dimensions=None):\n                 else:\n                     im = Image.open(tempfile_path)\n \n-                # I've seen some exceptions from the PIL library when trying to save palletted\n-                # PNG files to JPEG. Per the google-universe, they suggest converting to RGB first.\n-                im = im.convert('RGB')\n+                # We use the context processor here to avoid leaking the inner file descriptor\n+                # of the Image object -- this way it gets closed after we're done with using it.\n+                thumbnail_file = StringIO.StringIO()\n+                with im:","path":"common/lib/xmodule/xmodule/contentstore/content.py","position":73,"original_position":73,"commit_id":"46e094fc1a55646dfd084ce35f8c574e55218245","original_commit_id":"46e094fc1a55646dfd084ce35f8c574e55218245","user":{"login":"nedbat","id":23789,"avatar_url":"https://avatars.githubusercontent.com/u/23789?v=3","gravatar_id":"","url":"https://api.github.com/users/nedbat","html_url":"https://github.com/nedbat","followers_url":"https://api.github.com/users/nedbat/followers","following_url":"https://api.github.com/users/nedbat/following{/other_user}","gists_url":"https://api.github.com/users/nedbat/gists{/gist_id}","starred_url":"https://api.github.com/users/nedbat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nedbat/subscriptions","organizations_url":"https://api.github.com/users/nedbat/orgs","repos_url":"https://api.github.com/users/nedbat/repos","events_url":"https://api.github.com/users/nedbat/events{/privacy}","received_events_url":"https://api.github.com/users/nedbat/received_events","type":"User","site_admin":false},"body":"This is unusual, but looks like a fine way to ensure the resource is closed when we have two different ways to open the resource.  Usually the with-statement opens the resource, but the important thing is that it will close the resource.  I'd prefer not reusing the \"im\" name like this here, since it looks like the with statement will close the newly converted image, rather than the original source image.","created_at":"2016-06-02T13:19:58Z","updated_at":"2016-06-02T13:19:58Z","html_url":"https://github.com/edx/edx-platform/pull/12559#discussion_r65537168","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/12559","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/65537168"},"html":{"href":"https://github.com/edx/edx-platform/pull/12559#discussion_r65537168"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12559"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/12559","id":71418904,"html_url":"https://github.com/edx/edx-platform/pull/12559","diff_url":"https://github.com/edx/edx-platform/pull/12559.diff","patch_url":"https://github.com/edx/edx-platform/pull/12559.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/12559","number":12559,"state":"open","locked":false,"title":"[TNL-3960] Fix for thumbnail generation code crashing with SVG files","user":{"login":"jkozera","id":120114,"avatar_url":"https://avatars.githubusercontent.com/u/120114?v=3","gravatar_id":"","url":"https://api.github.com/users/jkozera","html_url":"https://github.com/jkozera","followers_url":"https://api.github.com/users/jkozera/followers","following_url":"https://api.github.com/users/jkozera/following{/other_user}","gists_url":"https://api.github.com/users/jkozera/gists{/gist_id}","starred_url":"https://api.github.com/users/jkozera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkozera/subscriptions","organizations_url":"https://api.github.com/users/jkozera/orgs","repos_url":"https://api.github.com/users/jkozera/repos","events_url":"https://api.github.com/users/jkozera/events{/privacy}","received_events_url":"https://api.github.com/users/jkozera/received_events","type":"User","site_admin":false},"body":"**Background**: As reported in [TNL-3960](https://openedx.atlassian.net/browse/TNL-3960), adding an SVG file to assets results in a logged exception while generating a thumbnail. A user-visible side effect is that no thumbnail is shown next to the uploaded file.\r\n\r\n**Studio Updates**: Assets view now shows thumbnails of uploaded SVG files.\r\n\r\n**LMS Updates**: None.\r\n\r\n**Testing**: Try uploading an SVG file in \"Content -> Files & Uploads\". A thumbnail should appear next to the file on the list.\r\n\r\n**Concerns**: As [mentioned](https://openedx.atlassian.net/browse/TNL-3960?focusedCommentId=191419&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-191419) on JIRA, IE11 does not always display SVG files correctly, but that is not a regression. Also displaying many, large, or complex SVG files in the list could have a client-side performance penalty, but assuming reasonable uploads, it should not be an issue.\r\n\r\nThe screenshot below demonstrates thumbnails of SVG files now being displayed (MS Edge - right side), and the above-mentioned IE11 (left side) not displaying some thumbnails.\r\n\r\n![screenshot from 2016-05-24 23-24-01](https://cloud.githubusercontent.com/assets/120114/15547169/e6a3f7ee-22a2-11e6-88d4-37a1cfce4ff1.png)\r\n","created_at":"2016-05-25T16:06:33Z","updated_at":"2016-06-02T13:19:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7894d362d36d953f0968188c6a0a82421d4a59f5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/12559/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/12559/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/12559/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/46e094fc1a55646dfd084ce35f8c574e55218245","head":{"label":"jkozera:svg-thumbnail-generation","ref":"svg-thumbnail-generation","sha":"46e094fc1a55646dfd084ce35f8c574e55218245","user":{"login":"jkozera","id":120114,"avatar_url":"https://avatars.githubusercontent.com/u/120114?v=3","gravatar_id":"","url":"https://api.github.com/users/jkozera","html_url":"https://github.com/jkozera","followers_url":"https://api.github.com/users/jkozera/followers","following_url":"https://api.github.com/users/jkozera/following{/other_user}","gists_url":"https://api.github.com/users/jkozera/gists{/gist_id}","starred_url":"https://api.github.com/users/jkozera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkozera/subscriptions","organizations_url":"https://api.github.com/users/jkozera/orgs","repos_url":"https://api.github.com/users/jkozera/repos","events_url":"https://api.github.com/users/jkozera/events{/privacy}","received_events_url":"https://api.github.com/users/jkozera/received_events","type":"User","site_admin":false},"repo":{"id":59677395,"name":"edx-platform","full_name":"jkozera/edx-platform","owner":{"login":"jkozera","id":120114,"avatar_url":"https://avatars.githubusercontent.com/u/120114?v=3","gravatar_id":"","url":"https://api.github.com/users/jkozera","html_url":"https://github.com/jkozera","followers_url":"https://api.github.com/users/jkozera/followers","following_url":"https://api.github.com/users/jkozera/following{/other_user}","gists_url":"https://api.github.com/users/jkozera/gists{/gist_id}","starred_url":"https://api.github.com/users/jkozera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkozera/subscriptions","organizations_url":"https://api.github.com/users/jkozera/orgs","repos_url":"https://api.github.com/users/jkozera/repos","events_url":"https://api.github.com/users/jkozera/events{/privacy}","received_events_url":"https://api.github.com/users/jkozera/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jkozera/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":true,"url":"https://api.github.com/repos/jkozera/edx-platform","forks_url":"https://api.github.com/repos/jkozera/edx-platform/forks","keys_url":"https://api.github.com/repos/jkozera/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jkozera/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jkozera/edx-platform/teams","hooks_url":"https://api.github.com/repos/jkozera/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/jkozera/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/jkozera/edx-platform/events","assignees_url":"https://api.github.com/repos/jkozera/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/jkozera/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/jkozera/edx-platform/tags","blobs_url":"https://api.github.com/repos/jkozera/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jkozera/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jkozera/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/jkozera/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jkozera/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/jkozera/edx-platform/languages","stargazers_url":"https://api.github.com/repos/jkozera/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/jkozera/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/jkozera/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/jkozera/edx-platform/subscription","commits_url":"https://api.github.com/repos/jkozera/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/jkozera/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/jkozera/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/jkozera/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/jkozera/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/jkozera/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jkozera/edx-platform/merges","archive_url":"https://api.github.com/repos/jkozera/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jkozera/edx-platform/downloads","issues_url":"https://api.github.com/repos/jkozera/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/jkozera/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/jkozera/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/jkozera/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jkozera/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/jkozera/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/jkozera/edx-platform/deployments","created_at":"2016-05-25T15:59:08Z","updated_at":"2016-05-25T15:59:42Z","pushed_at":"2016-06-01T19:59:18Z","git_url":"git://github.com/jkozera/edx-platform.git","ssh_url":"git@github.com:jkozera/edx-platform.git","clone_url":"https://github.com/jkozera/edx-platform.git","svn_url":"https://github.com/jkozera/edx-platform","homepage":"http://open.edx.org/","size":650560,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"f99723817b403c3ab1ba3833fcb18ff8a17c5c08","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2016-06-02T10:28:22Z","pushed_at":"2016-06-02T13:14:52Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":763855,"stargazers_count":2598,"watchers_count":2598,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1583,"mirror_url":null,"open_issues_count":164,"forks":1583,"open_issues":164,"watchers":2598,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12559"},"html":{"href":"https://github.com/edx/edx-platform/pull/12559"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/12559"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/12559/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12559/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/12559/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/46e094fc1a55646dfd084ce35f8c574e55218245"}}}}
{"actor":{"display_login":"nedbat"}}